SlideShare a Scribd company logo
import java.util.Scanner;
public class Main {
public static int gridArray1[][] = null;
public static int gridArray2[][] = null;
public static boolean playerTurn = true;
public static int count = 0;
public static void setGridDimensions(int x_max, int y_max) {
Main.gridArray1 = new int[x_max][y_max];
Main.gridArray2 = new int[x_max][y_max];
for (int i = 0; i < x_max; i++) {
for (int j = 0; j < y_max; j++) {
gridArray1[i][j] = -1;
gridArray2[i][j] = -1;
}
}
}
static void placeShip(int starting_x, int starting_y, int length, int direction) {
count++;
int ships[] = new int[10];
int battleshipArrayPositions1[] = new int[4];
int cruiserArrayPositions1[] = new int[3];
int submarineArrayPositions1[] = new int[3];
int destroyerArrayPositions1[] = new int[2];
int carrierArrayPositions2[] = new int[5];
int battleshipArrayPositions2[] = new int[4];
int cruiserArrayPositions2[] = new int[3];
int submarineArrayPositions2[] = new int[3];
int destroyerArrayPositions2[] = new int[2];
if (playerTurn) {
if (direction == 0) {
for (int i = starting_x; i < starting_x + length; i++) {
Main.gridArray1[i][starting_y] = 0;
}
} else {
for (int i = starting_y; i < starting_y + length; i++) {
Main.gridArray1[starting_x][i] = 0;
}
}
} else {
if (direction == 0) {
for (int i = starting_x; i < starting_x + length; i++) {
Main.gridArray2[i][starting_y] = 0;
}
} else {
for (int i = starting_y; i < starting_y + length; i++) {
Main.gridArray2[starting_x][i] = 0;
}
}
}
}
boolean isConflictingShipPlacement(int starting_x, int starting_y, int length, int direction) {
return false;
}
static int shoot(int x, int y) {
if (playerTurn) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (Main.gridArray2[i][j] == 0) {
return 0;
}
}
}
} else {
}
return 0;
}
boolean hasBeenAttempted(int x, int y) {
return false;
}
static void displayGrid(boolean showShips) {
int count = 0;
System.out.print(" 0 1 2 3 4 5 6 7 8 9");
if (showShips) {
if (playerTurn) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j % 10 == 0) {
System.out.print(" " + count + " ");
count++;
}
if (Main.gridArray1[i][j] == -1) {
System.out.print("- ");
} else if (Main.gridArray1[i][j] == 0) {
System.out.print("@ ");
} else if (Main.gridArray1[i][j] == 1) {
System.out.print("+ ");
} else {
System.out.print("X ");
}
}
}
} else {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j % 10 == 0) {
System.out.print(" " + count + " ");
count++;
}
if (Main.gridArray2[i][j] == -1) {
System.out.print("- ");
} else if (Main.gridArray2[i][j] == 0) {
System.out.print("@ ");
} else if (Main.gridArray2[i][j] == 1) {
System.out.print("+ ");
} else {
System.out.print("X ");
}
}
}
}
} else {
if (playerTurn) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j % 10 == 0) {
System.out.print(" " + count + " ");
count++;
}
if (Main.gridArray1[i][j] == -1) {
System.out.print("- ");
} else if (Main.gridArray1[i][j] == 0) {
System.out.print("- ");
} else if (Main.gridArray1[i][j] == 1) {
System.out.print("+ ");
} else {
System.out.print("X ");
}
}
}
} else {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j % 10 == 0) {
System.out.print(" " + count + " ");
count++;
}
if (Main.gridArray2[i][j] == -1) {
System.out.print("- ");
} else if (Main.gridArray2[i][j] == 0) {
System.out.print("- ");
} else if (Main.gridArray2[i][j] == 1) {
System.out.print("+ ");
} else {
System.out.print("X ");
}
}
}
}
}
System.out.println("");
}
public static void main(String[] args) {
int carrierLength = 5, battleshipLength = 4, cruiserLength = 3, submarineLength = 3,
destroyerLength = 2,
countPlayer1 = 5, countPlayer2 = 5, x, y, carrierDirectionNumber,
battleshipDirectionNumber,
cruiserDirectionNumber, submarineDirectionNumber, destroyerDirectionNumber,
shotReturn;
String carrier, battleship, cruiser, submarine, destroyer, carrierDirection,
battleshipDirection,
cruiserDirection, submarineDirection, destroyerDirection, shot;
setGridDimensions(10, 10);
Scanner scan = new Scanner(System.in);
for (int i = 0; i <= 1; i++) {
if (playerTurn) {
System.out.println("PLAYER 1 TURN");
displayGrid(true);
System.out.println("Place your Carrier (length 5): ");
carrier = scan.nextLine();
String carrierArray[] = carrier.split(",");
x = Integer.valueOf(carrierArray[0]);
y = Integer.valueOf(carrierArray[1]);
System.out.println("Choose direction (d/r): ");
carrierDirection = scan.nextLine();
if (carrierDirection.equals("d")) {
carrierDirection = "0";
} else {
carrierDirection = "1";
}
carrierDirectionNumber = Integer.valueOf(carrierDirection);
placeShip(x, y, carrierLength, carrierDirectionNumber);
displayGrid(true);
System.out.println("Place your Battleship (length 4): ");
battleship = scan.nextLine();
String battleshipArray[] = battleship.split(",");
x = Integer.valueOf(battleshipArray[0]);
y = Integer.valueOf(battleshipArray[1]);
System.out.println("Choose direction (d/r): ");
battleshipDirection = scan.nextLine();
if (battleshipDirection.equals("d")) {
battleshipDirection = "0";
} else {
battleshipDirection = "1";
}
battleshipDirectionNumber = Integer.valueOf(battleshipDirection);
placeShip(x, y, battleshipLength, battleshipDirectionNumber);
displayGrid(true);
System.out.println("Place your Cruiser (length 3): ");
cruiser = scan.nextLine();
String cruiserArray[] = cruiser.split(",");
x = Integer.valueOf(cruiserArray[0]);
y = Integer.valueOf(cruiserArray[1]);
System.out.println("Choose direction (d/r): ");
cruiserDirection = scan.nextLine();
if (cruiserDirection.equals("d")) {
cruiserDirection = "0";
} else {
cruiserDirection = "1";
}
cruiserDirectionNumber = Integer.valueOf(cruiserDirection);
placeShip(x, y, cruiserLength, cruiserDirectionNumber);
displayGrid(true);
System.out.println("Place your Submarine (length 3): ");
submarine = scan.nextLine();
String submarineArray[] = submarine.split(",");
x = Integer.valueOf(submarineArray[0]);
y = Integer.valueOf(submarineArray[1]);
System.out.println("Choose direction (d/r): ");
submarineDirection = scan.nextLine();
if (submarineDirection.equals("d")) {
submarineDirection = "0";
} else {
submarineDirection = "1";
}
submarineDirectionNumber = Integer.valueOf(submarineDirection);
placeShip(x, y, submarineLength, submarineDirectionNumber);
displayGrid(true);
System.out.println("Place your Destroyer (length 2): ");
destroyer = scan.nextLine();
String destroyerArray[] = destroyer.split(",");
x = Integer.valueOf(destroyerArray[0]);
y = Integer.valueOf(destroyerArray[1]);
System.out.println("Choose direction (d/r): ");
destroyerDirection = scan.nextLine();
if (destroyerDirection.equals("d")) {
destroyerDirection = "0";
} else {
destroyerDirection = "1";
}
destroyerDirectionNumber = Integer.valueOf(destroyerDirection);
placeShip(x, y, destroyerLength, destroyerDirectionNumber);
displayGrid(true);
playerTurn = false;
} else {
System.out.println("PLAYER 2 TURN");
displayGrid(true);
System.out.println("Place your Carrier (length 5): ");
carrier = scan.nextLine();
String carrierArray[] = carrier.split(",");
x = Integer.valueOf(carrierArray[0]);
y = Integer.valueOf(carrierArray[1]);
System.out.println("Choose direction (d/r): ");
carrierDirection = scan.nextLine();
if (carrierDirection.equals("d")) {
carrierDirection = "0";
} else {
carrierDirection = "1";
}
carrierDirectionNumber = Integer.valueOf(carrierDirection);
placeShip(x, y, carrierLength, carrierDirectionNumber);
displayGrid(true);
System.out.println("Place your Battleship (length 4): ");
battleship = scan.nextLine();
String battleshipArray[] = battleship.split(",");
x = Integer.valueOf(battleshipArray[0]);
y = Integer.valueOf(battleshipArray[1]);
System.out.println("Choose direction (d/r): ");
battleshipDirection = scan.nextLine();
if (battleshipDirection.equals("d")) {
battleshipDirection = "0";
} else {
battleshipDirection = "1";
}
battleshipDirectionNumber = Integer.valueOf(battleshipDirection);
placeShip(x, y, battleshipLength, battleshipDirectionNumber);
displayGrid(true);
System.out.println("Place your Cruiser (length 3): ");
cruiser = scan.nextLine();
String cruiserArray[] = cruiser.split(",");
x = Integer.valueOf(cruiserArray[0]);
y = Integer.valueOf(cruiserArray[1]);
System.out.println("Choose direction (d/r): ");
cruiserDirection = scan.nextLine();
if (cruiserDirection.equals("d")) {
cruiserDirection = "0";
} else {
cruiserDirection = "1";
}
cruiserDirectionNumber = Integer.valueOf(cruiserDirection);
placeShip(x, y, cruiserLength, cruiserDirectionNumber);
displayGrid(true);
System.out.println("Place your Submarine (length 3): ");
submarine = scan.nextLine();
String submarineArray[] = submarine.split(",");
x = Integer.valueOf(submarineArray[0]);
y = Integer.valueOf(submarineArray[1]);
System.out.println("Choose direction (d/r): ");
submarineDirection = scan.nextLine();
if (submarineDirection.equals("d")) {
submarineDirection = "0";
} else {
submarineDirection = "1";
}
submarineDirectionNumber = Integer.valueOf(submarineDirection);
placeShip(x, y, submarineLength, submarineDirectionNumber);
displayGrid(true);
System.out.println("Place your Destroyer (length 2): ");
destroyer = scan.nextLine();
String destroyerArray[] = destroyer.split(",");
x = Integer.valueOf(destroyerArray[0]);
y = Integer.valueOf(destroyerArray[1]);
System.out.println("Choose direction (d/r): ");
destroyerDirection = scan.nextLine();
if (destroyerDirection.equals("d")) {
destroyerDirection = "0";
} else {
destroyerDirection = "1";
}
destroyerDirectionNumber = Integer.valueOf(destroyerDirection);
placeShip(x, y, destroyerLength, destroyerDirectionNumber);
displayGrid(true);
}
}
while (countPlayer1 != 0 || countPlayer2 != 0) {
if (playerTurn) {
System.out.println("PLAYER 1 TURN");
System.out.println("Take a shot: ");
shot = scan.nextLine();
String shotArray[] = shot.split(",");
x = Integer.valueOf(shotArray[0]);
y = Integer.valueOf(shotArray[1]);
shotReturn = shoot(x, y);
if (shotReturn == -1) {
System.out.println("Miss!");
} else if (shotReturn == 0) {
System.out.println("Hit!");
countPlayer2--;
} else {
System.out.println("Ship sank!");
}
playerTurn = false;
} else {
System.out.println("PLAYER 2 TURN");
System.out.println("Take a shot: ");
shot = scan.nextLine();
String shotArray[] = shot.split(",");
x = Integer.valueOf(shotArray[0]);
y = Integer.valueOf(shotArray[1]);
shotReturn = shoot(x, y);
if (shotReturn == -1) {
System.out.println("Miss!");
} else if (shotReturn == 0) {
System.out.println("Hit!");
countPlayer1--;
} else {
System.out.println("Ship sank!");
}
playerTurn = true;
}
}
}
}
Solution
import java.util.Scanner;
public class Main {
public static int gridArray1[][] = null;
public static int gridArray2[][] = null;
public static boolean playerTurn = true;
public static int count = 0;
public static void setGridDimensions(int x_max, int y_max) {
Main.gridArray1 = new int[x_max][y_max];
Main.gridArray2 = new int[x_max][y_max];
for (int i = 0; i < x_max; i++) {
for (int j = 0; j < y_max; j++) {
gridArray1[i][j] = -1;
gridArray2[i][j] = -1;
}
}
}
static void placeShip(int starting_x, int starting_y, int length, int direction) {
count++;
int ships[] = new int[10];
int battleshipArrayPositions1[] = new int[4];
int cruiserArrayPositions1[] = new int[3];
int submarineArrayPositions1[] = new int[3];
int destroyerArrayPositions1[] = new int[2];
int carrierArrayPositions2[] = new int[5];
int battleshipArrayPositions2[] = new int[4];
int cruiserArrayPositions2[] = new int[3];
int submarineArrayPositions2[] = new int[3];
int destroyerArrayPositions2[] = new int[2];
if (playerTurn) {
if (direction == 0) {
for (int i = starting_x; i < starting_x + length; i++) {
Main.gridArray1[i][starting_y] = 0;
}
} else {
for (int i = starting_y; i < starting_y + length; i++) {
Main.gridArray1[starting_x][i] = 0;
}
}
} else {
if (direction == 0) {
for (int i = starting_x; i < starting_x + length; i++) {
Main.gridArray2[i][starting_y] = 0;
}
} else {
for (int i = starting_y; i < starting_y + length; i++) {
Main.gridArray2[starting_x][i] = 0;
}
}
}
}
boolean isConflictingShipPlacement(int starting_x, int starting_y, int length, int direction) {
return false;
}
static int shoot(int x, int y) {
if (playerTurn) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (Main.gridArray2[i][j] == 0) {
return 0;
}
}
}
} else {
}
return 0;
}
boolean hasBeenAttempted(int x, int y) {
return false;
}
static void displayGrid(boolean showShips) {
int count = 0;
System.out.print(" 0 1 2 3 4 5 6 7 8 9");
if (showShips) {
if (playerTurn) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j % 10 == 0) {
System.out.print(" " + count + " ");
count++;
}
if (Main.gridArray1[i][j] == -1) {
System.out.print("- ");
} else if (Main.gridArray1[i][j] == 0) {
System.out.print("@ ");
} else if (Main.gridArray1[i][j] == 1) {
System.out.print("+ ");
} else {
System.out.print("X ");
}
}
}
} else {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j % 10 == 0) {
System.out.print(" " + count + " ");
count++;
}
if (Main.gridArray2[i][j] == -1) {
System.out.print("- ");
} else if (Main.gridArray2[i][j] == 0) {
System.out.print("@ ");
} else if (Main.gridArray2[i][j] == 1) {
System.out.print("+ ");
} else {
System.out.print("X ");
}
}
}
}
} else {
if (playerTurn) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j % 10 == 0) {
System.out.print(" " + count + " ");
count++;
}
if (Main.gridArray1[i][j] == -1) {
System.out.print("- ");
} else if (Main.gridArray1[i][j] == 0) {
System.out.print("- ");
} else if (Main.gridArray1[i][j] == 1) {
System.out.print("+ ");
} else {
System.out.print("X ");
}
}
}
} else {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j % 10 == 0) {
System.out.print(" " + count + " ");
count++;
}
if (Main.gridArray2[i][j] == -1) {
System.out.print("- ");
} else if (Main.gridArray2[i][j] == 0) {
System.out.print("- ");
} else if (Main.gridArray2[i][j] == 1) {
System.out.print("+ ");
} else {
System.out.print("X ");
}
}
}
}
}
System.out.println("");
}
public static void main(String[] args) {
int carrierLength = 5, battleshipLength = 4, cruiserLength = 3, submarineLength = 3,
destroyerLength = 2,
countPlayer1 = 5, countPlayer2 = 5, x, y, carrierDirectionNumber,
battleshipDirectionNumber,
cruiserDirectionNumber, submarineDirectionNumber, destroyerDirectionNumber,
shotReturn;
String carrier, battleship, cruiser, submarine, destroyer, carrierDirection,
battleshipDirection,
cruiserDirection, submarineDirection, destroyerDirection, shot;
setGridDimensions(10, 10);
Scanner scan = new Scanner(System.in);
for (int i = 0; i <= 1; i++) {
if (playerTurn) {
System.out.println("PLAYER 1 TURN");
displayGrid(true);
System.out.println("Place your Carrier (length 5): ");
carrier = scan.nextLine();
String carrierArray[] = carrier.split(",");
x = Integer.valueOf(carrierArray[0]);
y = Integer.valueOf(carrierArray[1]);
System.out.println("Choose direction (d/r): ");
carrierDirection = scan.nextLine();
if (carrierDirection.equals("d")) {
carrierDirection = "0";
} else {
carrierDirection = "1";
}
carrierDirectionNumber = Integer.valueOf(carrierDirection);
placeShip(x, y, carrierLength, carrierDirectionNumber);
displayGrid(true);
System.out.println("Place your Battleship (length 4): ");
battleship = scan.nextLine();
String battleshipArray[] = battleship.split(",");
x = Integer.valueOf(battleshipArray[0]);
y = Integer.valueOf(battleshipArray[1]);
System.out.println("Choose direction (d/r): ");
battleshipDirection = scan.nextLine();
if (battleshipDirection.equals("d")) {
battleshipDirection = "0";
} else {
battleshipDirection = "1";
}
battleshipDirectionNumber = Integer.valueOf(battleshipDirection);
placeShip(x, y, battleshipLength, battleshipDirectionNumber);
displayGrid(true);
System.out.println("Place your Cruiser (length 3): ");
cruiser = scan.nextLine();
String cruiserArray[] = cruiser.split(",");
x = Integer.valueOf(cruiserArray[0]);
y = Integer.valueOf(cruiserArray[1]);
System.out.println("Choose direction (d/r): ");
cruiserDirection = scan.nextLine();
if (cruiserDirection.equals("d")) {
cruiserDirection = "0";
} else {
cruiserDirection = "1";
}
cruiserDirectionNumber = Integer.valueOf(cruiserDirection);
placeShip(x, y, cruiserLength, cruiserDirectionNumber);
displayGrid(true);
System.out.println("Place your Submarine (length 3): ");
submarine = scan.nextLine();
String submarineArray[] = submarine.split(",");
x = Integer.valueOf(submarineArray[0]);
y = Integer.valueOf(submarineArray[1]);
System.out.println("Choose direction (d/r): ");
submarineDirection = scan.nextLine();
if (submarineDirection.equals("d")) {
submarineDirection = "0";
} else {
submarineDirection = "1";
}
submarineDirectionNumber = Integer.valueOf(submarineDirection);
placeShip(x, y, submarineLength, submarineDirectionNumber);
displayGrid(true);
System.out.println("Place your Destroyer (length 2): ");
destroyer = scan.nextLine();
String destroyerArray[] = destroyer.split(",");
x = Integer.valueOf(destroyerArray[0]);
y = Integer.valueOf(destroyerArray[1]);
System.out.println("Choose direction (d/r): ");
destroyerDirection = scan.nextLine();
if (destroyerDirection.equals("d")) {
destroyerDirection = "0";
} else {
destroyerDirection = "1";
}
destroyerDirectionNumber = Integer.valueOf(destroyerDirection);
placeShip(x, y, destroyerLength, destroyerDirectionNumber);
displayGrid(true);
playerTurn = false;
} else {
System.out.println("PLAYER 2 TURN");
displayGrid(true);
System.out.println("Place your Carrier (length 5): ");
carrier = scan.nextLine();
String carrierArray[] = carrier.split(",");
x = Integer.valueOf(carrierArray[0]);
y = Integer.valueOf(carrierArray[1]);
System.out.println("Choose direction (d/r): ");
carrierDirection = scan.nextLine();
if (carrierDirection.equals("d")) {
carrierDirection = "0";
} else {
carrierDirection = "1";
}
carrierDirectionNumber = Integer.valueOf(carrierDirection);
placeShip(x, y, carrierLength, carrierDirectionNumber);
displayGrid(true);
System.out.println("Place your Battleship (length 4): ");
battleship = scan.nextLine();
String battleshipArray[] = battleship.split(",");
x = Integer.valueOf(battleshipArray[0]);
y = Integer.valueOf(battleshipArray[1]);
System.out.println("Choose direction (d/r): ");
battleshipDirection = scan.nextLine();
if (battleshipDirection.equals("d")) {
battleshipDirection = "0";
} else {
battleshipDirection = "1";
}
battleshipDirectionNumber = Integer.valueOf(battleshipDirection);
placeShip(x, y, battleshipLength, battleshipDirectionNumber);
displayGrid(true);
System.out.println("Place your Cruiser (length 3): ");
cruiser = scan.nextLine();
String cruiserArray[] = cruiser.split(",");
x = Integer.valueOf(cruiserArray[0]);
y = Integer.valueOf(cruiserArray[1]);
System.out.println("Choose direction (d/r): ");
cruiserDirection = scan.nextLine();
if (cruiserDirection.equals("d")) {
cruiserDirection = "0";
} else {
cruiserDirection = "1";
}
cruiserDirectionNumber = Integer.valueOf(cruiserDirection);
placeShip(x, y, cruiserLength, cruiserDirectionNumber);
displayGrid(true);
System.out.println("Place your Submarine (length 3): ");
submarine = scan.nextLine();
String submarineArray[] = submarine.split(",");
x = Integer.valueOf(submarineArray[0]);
y = Integer.valueOf(submarineArray[1]);
System.out.println("Choose direction (d/r): ");
submarineDirection = scan.nextLine();
if (submarineDirection.equals("d")) {
submarineDirection = "0";
} else {
submarineDirection = "1";
}
submarineDirectionNumber = Integer.valueOf(submarineDirection);
placeShip(x, y, submarineLength, submarineDirectionNumber);
displayGrid(true);
System.out.println("Place your Destroyer (length 2): ");
destroyer = scan.nextLine();
String destroyerArray[] = destroyer.split(",");
x = Integer.valueOf(destroyerArray[0]);
y = Integer.valueOf(destroyerArray[1]);
System.out.println("Choose direction (d/r): ");
destroyerDirection = scan.nextLine();
if (destroyerDirection.equals("d")) {
destroyerDirection = "0";
} else {
destroyerDirection = "1";
}
destroyerDirectionNumber = Integer.valueOf(destroyerDirection);
placeShip(x, y, destroyerLength, destroyerDirectionNumber);
displayGrid(true);
}
}
while (countPlayer1 != 0 || countPlayer2 != 0) {
if (playerTurn) {
System.out.println("PLAYER 1 TURN");
System.out.println("Take a shot: ");
shot = scan.nextLine();
String shotArray[] = shot.split(",");
x = Integer.valueOf(shotArray[0]);
y = Integer.valueOf(shotArray[1]);
shotReturn = shoot(x, y);
if (shotReturn == -1) {
System.out.println("Miss!");
} else if (shotReturn == 0) {
System.out.println("Hit!");
countPlayer2--;
} else {
System.out.println("Ship sank!");
}
playerTurn = false;
} else {
System.out.println("PLAYER 2 TURN");
System.out.println("Take a shot: ");
shot = scan.nextLine();
String shotArray[] = shot.split(",");
x = Integer.valueOf(shotArray[0]);
y = Integer.valueOf(shotArray[1]);
shotReturn = shoot(x, y);
if (shotReturn == -1) {
System.out.println("Miss!");
} else if (shotReturn == 0) {
System.out.println("Hit!");
countPlayer1--;
} else {
System.out.println("Ship sank!");
}
playerTurn = true;
}
}
}
}

More Related Content

Similar to import java.util.Scanner;public class Main {    public static in.pdf

The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
asif1401
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
Ramachendran Logarajah
 
Ocr code
Ocr codeOcr code
Ocr code
wi7sonjoseph
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
anjandavid
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
calderoncasto9163
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
fazilfootsteps
 
MineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdfMineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdf
aniyathikitchen
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
Kandarp Tiwari
 
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
apexcomputer54
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
kokah57440
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
monikagupta18jan
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
GameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfGameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdf
aravlitraders2012
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
archana singh
 
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
British Council
 
Cpds lab
Cpds labCpds lab
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
actocomputer
 
662305 LAB12
662305 LAB12662305 LAB12
662305 LAB12
Nitigan Nakjuatong
 
week-21x
week-21xweek-21x

Similar to import java.util.Scanner;public class Main {    public static in.pdf (20)

The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Ocr code
Ocr codeOcr code
Ocr code
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
 
MineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdfMineSweeper.java public class MS { public static void main(Strin.pdf
MineSweeper.java public class MS { public static void main(Strin.pdf
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
GameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfGameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdf
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 
662305 LAB12
662305 LAB12662305 LAB12
662305 LAB12
 
week-21x
week-21xweek-21x
week-21x
 

More from anwarsadath111

(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
anwarsadath111
 
We use a base (in this case sodium bicarbonate) during the separatio.pdf
  We use a base (in this case sodium bicarbonate) during the separatio.pdf  We use a base (in this case sodium bicarbonate) during the separatio.pdf
We use a base (in this case sodium bicarbonate) during the separatio.pdf
anwarsadath111
 
While computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdfWhile computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdf
anwarsadath111
 
There are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdfThere are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdf
anwarsadath111
 
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdfThe water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
anwarsadath111
 
adsorb onto silica gel Solu.pdf
  adsorb onto silica gel                                      Solu.pdf  adsorb onto silica gel                                      Solu.pdf
adsorb onto silica gel Solu.pdf
anwarsadath111
 
Solution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdfSolution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdf
anwarsadath111
 
SF4SolutionSF4.pdf
SF4SolutionSF4.pdfSF4SolutionSF4.pdf
SF4SolutionSF4.pdf
anwarsadath111
 
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdfQuick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
anwarsadath111
 
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdfQues-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
anwarsadath111
 
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdfPart1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
anwarsadath111
 
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdfPerformance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
anwarsadath111
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
anwarsadath111
 
P = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfP = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdf
anwarsadath111
 
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdfOSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
anwarsadath111
 
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdfOption 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
anwarsadath111
 
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdfNH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
anwarsadath111
 
No. of shares outstanding = Total assets x weight of equity price .pdf
No. of shares outstanding = Total assets x weight of equity  price .pdfNo. of shares outstanding = Total assets x weight of equity  price .pdf
No. of shares outstanding = Total assets x weight of equity price .pdf
anwarsadath111
 
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
molarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdfmolarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdf
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
anwarsadath111
 
hi Q is nearly done,just give me dia of shaftSolutionhi Q is n.pdf
hi Q is nearly done,just give me dia of shaftSolutionhi Q is n.pdfhi Q is nearly done,just give me dia of shaftSolutionhi Q is n.pdf
hi Q is nearly done,just give me dia of shaftSolutionhi Q is n.pdf
anwarsadath111
 

More from anwarsadath111 (20)

(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
(1) c. Two-tailed test(2)d. Ho Men and women are the same in .pdf
 
We use a base (in this case sodium bicarbonate) during the separatio.pdf
  We use a base (in this case sodium bicarbonate) during the separatio.pdf  We use a base (in this case sodium bicarbonate) during the separatio.pdf
We use a base (in this case sodium bicarbonate) during the separatio.pdf
 
While computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdfWhile computing the dilluted earnings per share Dividend paid on Pre.pdf
While computing the dilluted earnings per share Dividend paid on Pre.pdf
 
There are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdfThere are several ways in which the gene regulation in eukaryotes di.pdf
There are several ways in which the gene regulation in eukaryotes di.pdf
 
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdfThe water must be boiled to remove traces of dissolved carbon dioxid.pdf
The water must be boiled to remove traces of dissolved carbon dioxid.pdf
 
adsorb onto silica gel Solu.pdf
  adsorb onto silica gel                                      Solu.pdf  adsorb onto silica gel                                      Solu.pdf
adsorb onto silica gel Solu.pdf
 
Solution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdfSolution Plants show different types of symptoms when there is an.pdf
Solution Plants show different types of symptoms when there is an.pdf
 
SF4SolutionSF4.pdf
SF4SolutionSF4.pdfSF4SolutionSF4.pdf
SF4SolutionSF4.pdf
 
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdfQuick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
Quick ratio = (Cash + accounts receivable)Accounts payableFor 200.pdf
 
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdfQues-1) What is the most likely cause of a throat infection in a 6-y.pdf
Ques-1) What is the most likely cause of a throat infection in a 6-y.pdf
 
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdfPart1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
Part1. Option 3rd; Somatic cells such as liver cells cannot undergo .pdf
 
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdfPerformance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
Performance RatiosMarket Value Added (MVA)MVA=(Company’s market.pdf
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
 
P = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfP = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdf
 
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdfOSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
OSI MODELIt has 7 layersINTERNET MODELIt has5 LayersDOD MO.pdf
 
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdfOption 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
Option 2 namely TPP contains a thiazolium ring is correct. This is b.pdf
 
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdfNH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
NH4NO3 = N2O + 2 H2OMoles of NH4NO3 = 12 x moles of H2O= 12 x .pdf
 
No. of shares outstanding = Total assets x weight of equity price .pdf
No. of shares outstanding = Total assets x weight of equity  price .pdfNo. of shares outstanding = Total assets x weight of equity  price .pdf
No. of shares outstanding = Total assets x weight of equity price .pdf
 
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
molarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdfmolarity = moles  volume = 2.0 x 10-3 mol  (18.51000) L = 0.11 M.pdf
molarity = moles volume = 2.0 x 10-3 mol (18.51000) L = 0.11 M.pdf
 
hi Q is nearly done,just give me dia of shaftSolutionhi Q is n.pdf
hi Q is nearly done,just give me dia of shaftSolutionhi Q is n.pdfhi Q is nearly done,just give me dia of shaftSolutionhi Q is n.pdf
hi Q is nearly done,just give me dia of shaftSolutionhi Q is n.pdf
 

Recently uploaded

Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 

Recently uploaded (20)

Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 

import java.util.Scanner;public class Main {    public static in.pdf

  • 1. import java.util.Scanner; public class Main { public static int gridArray1[][] = null; public static int gridArray2[][] = null; public static boolean playerTurn = true; public static int count = 0; public static void setGridDimensions(int x_max, int y_max) { Main.gridArray1 = new int[x_max][y_max]; Main.gridArray2 = new int[x_max][y_max]; for (int i = 0; i < x_max; i++) { for (int j = 0; j < y_max; j++) { gridArray1[i][j] = -1; gridArray2[i][j] = -1; } } } static void placeShip(int starting_x, int starting_y, int length, int direction) { count++; int ships[] = new int[10]; int battleshipArrayPositions1[] = new int[4]; int cruiserArrayPositions1[] = new int[3]; int submarineArrayPositions1[] = new int[3]; int destroyerArrayPositions1[] = new int[2]; int carrierArrayPositions2[] = new int[5]; int battleshipArrayPositions2[] = new int[4]; int cruiserArrayPositions2[] = new int[3]; int submarineArrayPositions2[] = new int[3]; int destroyerArrayPositions2[] = new int[2]; if (playerTurn) { if (direction == 0) { for (int i = starting_x; i < starting_x + length; i++) {
  • 2. Main.gridArray1[i][starting_y] = 0; } } else { for (int i = starting_y; i < starting_y + length; i++) { Main.gridArray1[starting_x][i] = 0; } } } else { if (direction == 0) { for (int i = starting_x; i < starting_x + length; i++) { Main.gridArray2[i][starting_y] = 0; } } else { for (int i = starting_y; i < starting_y + length; i++) { Main.gridArray2[starting_x][i] = 0; } } } } boolean isConflictingShipPlacement(int starting_x, int starting_y, int length, int direction) { return false; } static int shoot(int x, int y) { if (playerTurn) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (Main.gridArray2[i][j] == 0) { return 0; } } } } else { } return 0; } boolean hasBeenAttempted(int x, int y) {
  • 3. return false; } static void displayGrid(boolean showShips) { int count = 0; System.out.print(" 0 1 2 3 4 5 6 7 8 9"); if (showShips) { if (playerTurn) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j % 10 == 0) { System.out.print(" " + count + " "); count++; } if (Main.gridArray1[i][j] == -1) { System.out.print("- "); } else if (Main.gridArray1[i][j] == 0) { System.out.print("@ "); } else if (Main.gridArray1[i][j] == 1) { System.out.print("+ "); } else { System.out.print("X "); } } } } else { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j % 10 == 0) { System.out.print(" " + count + " "); count++; } if (Main.gridArray2[i][j] == -1) { System.out.print("- "); } else if (Main.gridArray2[i][j] == 0) { System.out.print("@ "); } else if (Main.gridArray2[i][j] == 1) {
  • 4. System.out.print("+ "); } else { System.out.print("X "); } } } } } else { if (playerTurn) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j % 10 == 0) { System.out.print(" " + count + " "); count++; } if (Main.gridArray1[i][j] == -1) { System.out.print("- "); } else if (Main.gridArray1[i][j] == 0) { System.out.print("- "); } else if (Main.gridArray1[i][j] == 1) { System.out.print("+ "); } else { System.out.print("X "); } } } } else { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j % 10 == 0) { System.out.print(" " + count + " "); count++; } if (Main.gridArray2[i][j] == -1) { System.out.print("- "); } else if (Main.gridArray2[i][j] == 0) {
  • 5. System.out.print("- "); } else if (Main.gridArray2[i][j] == 1) { System.out.print("+ "); } else { System.out.print("X "); } } } } } System.out.println(""); } public static void main(String[] args) { int carrierLength = 5, battleshipLength = 4, cruiserLength = 3, submarineLength = 3, destroyerLength = 2, countPlayer1 = 5, countPlayer2 = 5, x, y, carrierDirectionNumber, battleshipDirectionNumber, cruiserDirectionNumber, submarineDirectionNumber, destroyerDirectionNumber, shotReturn; String carrier, battleship, cruiser, submarine, destroyer, carrierDirection, battleshipDirection, cruiserDirection, submarineDirection, destroyerDirection, shot; setGridDimensions(10, 10); Scanner scan = new Scanner(System.in); for (int i = 0; i <= 1; i++) { if (playerTurn) { System.out.println("PLAYER 1 TURN"); displayGrid(true); System.out.println("Place your Carrier (length 5): "); carrier = scan.nextLine(); String carrierArray[] = carrier.split(","); x = Integer.valueOf(carrierArray[0]); y = Integer.valueOf(carrierArray[1]); System.out.println("Choose direction (d/r): "); carrierDirection = scan.nextLine(); if (carrierDirection.equals("d")) {
  • 6. carrierDirection = "0"; } else { carrierDirection = "1"; } carrierDirectionNumber = Integer.valueOf(carrierDirection); placeShip(x, y, carrierLength, carrierDirectionNumber); displayGrid(true); System.out.println("Place your Battleship (length 4): "); battleship = scan.nextLine(); String battleshipArray[] = battleship.split(","); x = Integer.valueOf(battleshipArray[0]); y = Integer.valueOf(battleshipArray[1]); System.out.println("Choose direction (d/r): "); battleshipDirection = scan.nextLine(); if (battleshipDirection.equals("d")) { battleshipDirection = "0"; } else { battleshipDirection = "1"; } battleshipDirectionNumber = Integer.valueOf(battleshipDirection); placeShip(x, y, battleshipLength, battleshipDirectionNumber); displayGrid(true); System.out.println("Place your Cruiser (length 3): "); cruiser = scan.nextLine(); String cruiserArray[] = cruiser.split(","); x = Integer.valueOf(cruiserArray[0]); y = Integer.valueOf(cruiserArray[1]); System.out.println("Choose direction (d/r): "); cruiserDirection = scan.nextLine(); if (cruiserDirection.equals("d")) { cruiserDirection = "0"; } else { cruiserDirection = "1"; } cruiserDirectionNumber = Integer.valueOf(cruiserDirection); placeShip(x, y, cruiserLength, cruiserDirectionNumber);
  • 7. displayGrid(true); System.out.println("Place your Submarine (length 3): "); submarine = scan.nextLine(); String submarineArray[] = submarine.split(","); x = Integer.valueOf(submarineArray[0]); y = Integer.valueOf(submarineArray[1]); System.out.println("Choose direction (d/r): "); submarineDirection = scan.nextLine(); if (submarineDirection.equals("d")) { submarineDirection = "0"; } else { submarineDirection = "1"; } submarineDirectionNumber = Integer.valueOf(submarineDirection); placeShip(x, y, submarineLength, submarineDirectionNumber); displayGrid(true); System.out.println("Place your Destroyer (length 2): "); destroyer = scan.nextLine(); String destroyerArray[] = destroyer.split(","); x = Integer.valueOf(destroyerArray[0]); y = Integer.valueOf(destroyerArray[1]); System.out.println("Choose direction (d/r): "); destroyerDirection = scan.nextLine(); if (destroyerDirection.equals("d")) { destroyerDirection = "0"; } else { destroyerDirection = "1"; } destroyerDirectionNumber = Integer.valueOf(destroyerDirection); placeShip(x, y, destroyerLength, destroyerDirectionNumber); displayGrid(true); playerTurn = false; } else { System.out.println("PLAYER 2 TURN"); displayGrid(true); System.out.println("Place your Carrier (length 5): ");
  • 8. carrier = scan.nextLine(); String carrierArray[] = carrier.split(","); x = Integer.valueOf(carrierArray[0]); y = Integer.valueOf(carrierArray[1]); System.out.println("Choose direction (d/r): "); carrierDirection = scan.nextLine(); if (carrierDirection.equals("d")) { carrierDirection = "0"; } else { carrierDirection = "1"; } carrierDirectionNumber = Integer.valueOf(carrierDirection); placeShip(x, y, carrierLength, carrierDirectionNumber); displayGrid(true); System.out.println("Place your Battleship (length 4): "); battleship = scan.nextLine(); String battleshipArray[] = battleship.split(","); x = Integer.valueOf(battleshipArray[0]); y = Integer.valueOf(battleshipArray[1]); System.out.println("Choose direction (d/r): "); battleshipDirection = scan.nextLine(); if (battleshipDirection.equals("d")) { battleshipDirection = "0"; } else { battleshipDirection = "1"; } battleshipDirectionNumber = Integer.valueOf(battleshipDirection); placeShip(x, y, battleshipLength, battleshipDirectionNumber); displayGrid(true); System.out.println("Place your Cruiser (length 3): "); cruiser = scan.nextLine(); String cruiserArray[] = cruiser.split(","); x = Integer.valueOf(cruiserArray[0]); y = Integer.valueOf(cruiserArray[1]); System.out.println("Choose direction (d/r): "); cruiserDirection = scan.nextLine();
  • 9. if (cruiserDirection.equals("d")) { cruiserDirection = "0"; } else { cruiserDirection = "1"; } cruiserDirectionNumber = Integer.valueOf(cruiserDirection); placeShip(x, y, cruiserLength, cruiserDirectionNumber); displayGrid(true); System.out.println("Place your Submarine (length 3): "); submarine = scan.nextLine(); String submarineArray[] = submarine.split(","); x = Integer.valueOf(submarineArray[0]); y = Integer.valueOf(submarineArray[1]); System.out.println("Choose direction (d/r): "); submarineDirection = scan.nextLine(); if (submarineDirection.equals("d")) { submarineDirection = "0"; } else { submarineDirection = "1"; } submarineDirectionNumber = Integer.valueOf(submarineDirection); placeShip(x, y, submarineLength, submarineDirectionNumber); displayGrid(true); System.out.println("Place your Destroyer (length 2): "); destroyer = scan.nextLine(); String destroyerArray[] = destroyer.split(","); x = Integer.valueOf(destroyerArray[0]); y = Integer.valueOf(destroyerArray[1]); System.out.println("Choose direction (d/r): "); destroyerDirection = scan.nextLine(); if (destroyerDirection.equals("d")) { destroyerDirection = "0"; } else { destroyerDirection = "1"; } destroyerDirectionNumber = Integer.valueOf(destroyerDirection);
  • 10. placeShip(x, y, destroyerLength, destroyerDirectionNumber); displayGrid(true); } } while (countPlayer1 != 0 || countPlayer2 != 0) { if (playerTurn) { System.out.println("PLAYER 1 TURN"); System.out.println("Take a shot: "); shot = scan.nextLine(); String shotArray[] = shot.split(","); x = Integer.valueOf(shotArray[0]); y = Integer.valueOf(shotArray[1]); shotReturn = shoot(x, y); if (shotReturn == -1) { System.out.println("Miss!"); } else if (shotReturn == 0) { System.out.println("Hit!"); countPlayer2--; } else { System.out.println("Ship sank!"); } playerTurn = false; } else { System.out.println("PLAYER 2 TURN"); System.out.println("Take a shot: "); shot = scan.nextLine(); String shotArray[] = shot.split(","); x = Integer.valueOf(shotArray[0]); y = Integer.valueOf(shotArray[1]); shotReturn = shoot(x, y); if (shotReturn == -1) { System.out.println("Miss!"); } else if (shotReturn == 0) { System.out.println("Hit!"); countPlayer1--; } else {
  • 11. System.out.println("Ship sank!"); } playerTurn = true; } } } } Solution import java.util.Scanner; public class Main { public static int gridArray1[][] = null; public static int gridArray2[][] = null; public static boolean playerTurn = true; public static int count = 0; public static void setGridDimensions(int x_max, int y_max) { Main.gridArray1 = new int[x_max][y_max]; Main.gridArray2 = new int[x_max][y_max]; for (int i = 0; i < x_max; i++) { for (int j = 0; j < y_max; j++) { gridArray1[i][j] = -1; gridArray2[i][j] = -1; } } } static void placeShip(int starting_x, int starting_y, int length, int direction) { count++; int ships[] = new int[10]; int battleshipArrayPositions1[] = new int[4]; int cruiserArrayPositions1[] = new int[3]; int submarineArrayPositions1[] = new int[3]; int destroyerArrayPositions1[] = new int[2];
  • 12. int carrierArrayPositions2[] = new int[5]; int battleshipArrayPositions2[] = new int[4]; int cruiserArrayPositions2[] = new int[3]; int submarineArrayPositions2[] = new int[3]; int destroyerArrayPositions2[] = new int[2]; if (playerTurn) { if (direction == 0) { for (int i = starting_x; i < starting_x + length; i++) { Main.gridArray1[i][starting_y] = 0; } } else { for (int i = starting_y; i < starting_y + length; i++) { Main.gridArray1[starting_x][i] = 0; } } } else { if (direction == 0) { for (int i = starting_x; i < starting_x + length; i++) { Main.gridArray2[i][starting_y] = 0; } } else { for (int i = starting_y; i < starting_y + length; i++) { Main.gridArray2[starting_x][i] = 0; } } } } boolean isConflictingShipPlacement(int starting_x, int starting_y, int length, int direction) { return false; } static int shoot(int x, int y) { if (playerTurn) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (Main.gridArray2[i][j] == 0) {
  • 13. return 0; } } } } else { } return 0; } boolean hasBeenAttempted(int x, int y) { return false; } static void displayGrid(boolean showShips) { int count = 0; System.out.print(" 0 1 2 3 4 5 6 7 8 9"); if (showShips) { if (playerTurn) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j % 10 == 0) { System.out.print(" " + count + " "); count++; } if (Main.gridArray1[i][j] == -1) { System.out.print("- "); } else if (Main.gridArray1[i][j] == 0) { System.out.print("@ "); } else if (Main.gridArray1[i][j] == 1) { System.out.print("+ "); } else { System.out.print("X "); } } } } else { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) {
  • 14. if (j % 10 == 0) { System.out.print(" " + count + " "); count++; } if (Main.gridArray2[i][j] == -1) { System.out.print("- "); } else if (Main.gridArray2[i][j] == 0) { System.out.print("@ "); } else if (Main.gridArray2[i][j] == 1) { System.out.print("+ "); } else { System.out.print("X "); } } } } } else { if (playerTurn) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j % 10 == 0) { System.out.print(" " + count + " "); count++; } if (Main.gridArray1[i][j] == -1) { System.out.print("- "); } else if (Main.gridArray1[i][j] == 0) { System.out.print("- "); } else if (Main.gridArray1[i][j] == 1) { System.out.print("+ "); } else { System.out.print("X "); } } } } else {
  • 15. for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j % 10 == 0) { System.out.print(" " + count + " "); count++; } if (Main.gridArray2[i][j] == -1) { System.out.print("- "); } else if (Main.gridArray2[i][j] == 0) { System.out.print("- "); } else if (Main.gridArray2[i][j] == 1) { System.out.print("+ "); } else { System.out.print("X "); } } } } } System.out.println(""); } public static void main(String[] args) { int carrierLength = 5, battleshipLength = 4, cruiserLength = 3, submarineLength = 3, destroyerLength = 2, countPlayer1 = 5, countPlayer2 = 5, x, y, carrierDirectionNumber, battleshipDirectionNumber, cruiserDirectionNumber, submarineDirectionNumber, destroyerDirectionNumber, shotReturn; String carrier, battleship, cruiser, submarine, destroyer, carrierDirection, battleshipDirection, cruiserDirection, submarineDirection, destroyerDirection, shot; setGridDimensions(10, 10); Scanner scan = new Scanner(System.in); for (int i = 0; i <= 1; i++) { if (playerTurn) { System.out.println("PLAYER 1 TURN");
  • 16. displayGrid(true); System.out.println("Place your Carrier (length 5): "); carrier = scan.nextLine(); String carrierArray[] = carrier.split(","); x = Integer.valueOf(carrierArray[0]); y = Integer.valueOf(carrierArray[1]); System.out.println("Choose direction (d/r): "); carrierDirection = scan.nextLine(); if (carrierDirection.equals("d")) { carrierDirection = "0"; } else { carrierDirection = "1"; } carrierDirectionNumber = Integer.valueOf(carrierDirection); placeShip(x, y, carrierLength, carrierDirectionNumber); displayGrid(true); System.out.println("Place your Battleship (length 4): "); battleship = scan.nextLine(); String battleshipArray[] = battleship.split(","); x = Integer.valueOf(battleshipArray[0]); y = Integer.valueOf(battleshipArray[1]); System.out.println("Choose direction (d/r): "); battleshipDirection = scan.nextLine(); if (battleshipDirection.equals("d")) { battleshipDirection = "0"; } else { battleshipDirection = "1"; } battleshipDirectionNumber = Integer.valueOf(battleshipDirection); placeShip(x, y, battleshipLength, battleshipDirectionNumber); displayGrid(true); System.out.println("Place your Cruiser (length 3): "); cruiser = scan.nextLine(); String cruiserArray[] = cruiser.split(","); x = Integer.valueOf(cruiserArray[0]); y = Integer.valueOf(cruiserArray[1]);
  • 17. System.out.println("Choose direction (d/r): "); cruiserDirection = scan.nextLine(); if (cruiserDirection.equals("d")) { cruiserDirection = "0"; } else { cruiserDirection = "1"; } cruiserDirectionNumber = Integer.valueOf(cruiserDirection); placeShip(x, y, cruiserLength, cruiserDirectionNumber); displayGrid(true); System.out.println("Place your Submarine (length 3): "); submarine = scan.nextLine(); String submarineArray[] = submarine.split(","); x = Integer.valueOf(submarineArray[0]); y = Integer.valueOf(submarineArray[1]); System.out.println("Choose direction (d/r): "); submarineDirection = scan.nextLine(); if (submarineDirection.equals("d")) { submarineDirection = "0"; } else { submarineDirection = "1"; } submarineDirectionNumber = Integer.valueOf(submarineDirection); placeShip(x, y, submarineLength, submarineDirectionNumber); displayGrid(true); System.out.println("Place your Destroyer (length 2): "); destroyer = scan.nextLine(); String destroyerArray[] = destroyer.split(","); x = Integer.valueOf(destroyerArray[0]); y = Integer.valueOf(destroyerArray[1]); System.out.println("Choose direction (d/r): "); destroyerDirection = scan.nextLine(); if (destroyerDirection.equals("d")) { destroyerDirection = "0"; } else { destroyerDirection = "1";
  • 18. } destroyerDirectionNumber = Integer.valueOf(destroyerDirection); placeShip(x, y, destroyerLength, destroyerDirectionNumber); displayGrid(true); playerTurn = false; } else { System.out.println("PLAYER 2 TURN"); displayGrid(true); System.out.println("Place your Carrier (length 5): "); carrier = scan.nextLine(); String carrierArray[] = carrier.split(","); x = Integer.valueOf(carrierArray[0]); y = Integer.valueOf(carrierArray[1]); System.out.println("Choose direction (d/r): "); carrierDirection = scan.nextLine(); if (carrierDirection.equals("d")) { carrierDirection = "0"; } else { carrierDirection = "1"; } carrierDirectionNumber = Integer.valueOf(carrierDirection); placeShip(x, y, carrierLength, carrierDirectionNumber); displayGrid(true); System.out.println("Place your Battleship (length 4): "); battleship = scan.nextLine(); String battleshipArray[] = battleship.split(","); x = Integer.valueOf(battleshipArray[0]); y = Integer.valueOf(battleshipArray[1]); System.out.println("Choose direction (d/r): "); battleshipDirection = scan.nextLine(); if (battleshipDirection.equals("d")) { battleshipDirection = "0"; } else { battleshipDirection = "1"; } battleshipDirectionNumber = Integer.valueOf(battleshipDirection);
  • 19. placeShip(x, y, battleshipLength, battleshipDirectionNumber); displayGrid(true); System.out.println("Place your Cruiser (length 3): "); cruiser = scan.nextLine(); String cruiserArray[] = cruiser.split(","); x = Integer.valueOf(cruiserArray[0]); y = Integer.valueOf(cruiserArray[1]); System.out.println("Choose direction (d/r): "); cruiserDirection = scan.nextLine(); if (cruiserDirection.equals("d")) { cruiserDirection = "0"; } else { cruiserDirection = "1"; } cruiserDirectionNumber = Integer.valueOf(cruiserDirection); placeShip(x, y, cruiserLength, cruiserDirectionNumber); displayGrid(true); System.out.println("Place your Submarine (length 3): "); submarine = scan.nextLine(); String submarineArray[] = submarine.split(","); x = Integer.valueOf(submarineArray[0]); y = Integer.valueOf(submarineArray[1]); System.out.println("Choose direction (d/r): "); submarineDirection = scan.nextLine(); if (submarineDirection.equals("d")) { submarineDirection = "0"; } else { submarineDirection = "1"; } submarineDirectionNumber = Integer.valueOf(submarineDirection); placeShip(x, y, submarineLength, submarineDirectionNumber); displayGrid(true); System.out.println("Place your Destroyer (length 2): "); destroyer = scan.nextLine(); String destroyerArray[] = destroyer.split(","); x = Integer.valueOf(destroyerArray[0]);
  • 20. y = Integer.valueOf(destroyerArray[1]); System.out.println("Choose direction (d/r): "); destroyerDirection = scan.nextLine(); if (destroyerDirection.equals("d")) { destroyerDirection = "0"; } else { destroyerDirection = "1"; } destroyerDirectionNumber = Integer.valueOf(destroyerDirection); placeShip(x, y, destroyerLength, destroyerDirectionNumber); displayGrid(true); } } while (countPlayer1 != 0 || countPlayer2 != 0) { if (playerTurn) { System.out.println("PLAYER 1 TURN"); System.out.println("Take a shot: "); shot = scan.nextLine(); String shotArray[] = shot.split(","); x = Integer.valueOf(shotArray[0]); y = Integer.valueOf(shotArray[1]); shotReturn = shoot(x, y); if (shotReturn == -1) { System.out.println("Miss!"); } else if (shotReturn == 0) { System.out.println("Hit!"); countPlayer2--; } else { System.out.println("Ship sank!"); } playerTurn = false; } else { System.out.println("PLAYER 2 TURN"); System.out.println("Take a shot: "); shot = scan.nextLine(); String shotArray[] = shot.split(",");
  • 21. x = Integer.valueOf(shotArray[0]); y = Integer.valueOf(shotArray[1]); shotReturn = shoot(x, y); if (shotReturn == -1) { System.out.println("Miss!"); } else if (shotReturn == 0) { System.out.println("Hit!"); countPlayer1--; } else { System.out.println("Ship sank!"); } playerTurn = true; } } } }