SlideShare a Scribd company logo
1 of 21
Download to read offline
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 {.pdfasif1401
 
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.pdfanjandavid
 
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.pdfcalderoncasto9163
 
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.pdffazilfootsteps
 
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.pdfaniyathikitchen
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C ProgramsKandarp 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.;.pdfapexcomputer54
 
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.pdfkokah57440
 
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;.pdfaravlitraders2012
 
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
 
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.pdfactocomputer
 

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 .pdfanwarsadath111
 
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.pdfanwarsadath111
 
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.pdfanwarsadath111
 
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.pdfanwarsadath111
 
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.pdfanwarsadath111
 
adsorb onto silica gel Solu.pdf
  adsorb onto silica gel                                      Solu.pdf  adsorb onto silica gel                                      Solu.pdf
adsorb onto silica gel Solu.pdfanwarsadath111
 
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.pdfanwarsadath111
 
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.pdfanwarsadath111
 
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.pdfanwarsadath111
 
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 .pdfanwarsadath111
 
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.pdfanwarsadath111
 
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 .pdfanwarsadath111
 
P = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfP = 212option ASolutionP = 212option A.pdf
P = 212option ASolutionP = 212option A.pdfanwarsadath111
 
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.pdfanwarsadath111
 
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.pdfanwarsadath111
 
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 .pdfanwarsadath111
 
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 .pdfanwarsadath111
 
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.pdfanwarsadath111
 
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.pdfanwarsadath111
 

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

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

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; } } } }