Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

All i need is a game that allows a user to input a row and column and have it ha

ID: 3743968 • Letter: A

Question

All i need is a game that allows a user to input a row and column and have it handle any input possible and to just print out the adjacent edges and corners and he not adjacent. Nothing more. I dont want a game that gives me hints. Just simply 3 methods for adjacent corners, edges and the not adjacent at all and have it parse so any imput is allow such as: (5, 5), 3 0, 4,1, a7, b 2

(every time i asked this question they answered a completely different thing and nothing i needed was in the code. Please help me make a simpple code with just what is asked (which is the adjacency data) nothing more

Battle Ship Game

Write a Java program from scratch.

Simple geometrical reasoning is at the core of Battleships. One important notion is adjacency, with two sub-types: edge adjacency and corner adjacency. For example, the square (4,3) is edge-adjacent to the square (3,3), it is corner-adjacent to the square (3,2), and it is not adjacent to the square (6,7).

Write a program that reads a square from the user, and prints out three lists(each with a seperate method):

1) a list of all edge-adjacent squares,

2) a list of all corner-adjacent squares, and

3) a list of all squares which are not adjacent at all.

Our version of battleships is played on a 9 by 9 board. The lower-left square is (0,0). As noted, the program will read from the console a shot specification. You can decide which formats to handle. They may include, for example, specifications like

(5, 5)

3 0

4,1

a7

b 2

An A-level program will handle all the input formats illustrated, output correct answers, be clearly written, and be well designed.

Explanation / Answer

If you want to output the points in the format it has been entered that can be done too.

Since it was not stated hence I have kept the constant format for the output (a,b). However any input format that has been specified has been handled. If the format is not one of those given, the program exits.

Modified Java Code:

import java.util.*;

import java.lang.*;

import java.io.*;

class Ideone

{

public static int[][] hashBoard = new int[9][9];

public static int format=0;

public static void printCoord(int x, int y)

{

char c = (char)(x+97);

switch(format)

{

case 1:

System.out.println("("+x+", "+y+")");

break;

case 2:

System.out.println(x+" "+y);

break;

case 3:

System.out.println(x+","+y);

break;

case 4:

System.out.println(c+""+y);

break;

case 5:

System.out.println(c+" "+y);

break;

}

}

public static void printCornerAdjacent(int x, int y)

{

System.out.println("Corner Adjacent Points :");

int nextX, nextY;

//Left Top corner

nextX=x-1; nextY=y-1;

if(nextX>=0 && nextY>=0){

printCoord(nextX, nextY);

hashBoard[nextX][nextY]=1;

}

//Right Top corner

nextX=x+1; nextY=y-1;

if(nextX<9 && nextY>=0){

printCoord(nextX, nextY);

hashBoard[nextX][nextY]=1;

}

//Left Down corner

nextX=x-1; nextY=y+1;

if(nextX>=0 && nextY<9){

printCoord(nextX, nextY);

hashBoard[nextX][nextY]=1;

}

//Right Down corner

nextX=x+1; nextY=y+1;

if(nextX<9 && nextY<9){

printCoord(nextX, nextY);

hashBoard[nextX][nextY]=1;

}

}

public static void printEdgeAdjacent(int x, int y)

{

System.out.println("Edge Adjacent Points :");

int nextX, nextY;

//Left

nextX=x-1; nextY=y;

if(nextX>=0){

printCoord(nextX, nextY);

hashBoard[nextX][nextY]=1;

}

//Right

nextX=x+1; nextY=y;

if(nextX<9){

printCoord(nextX, nextY);

hashBoard[nextX][nextY]=1;

}

//Top

nextX=x; nextY=y-1;

if(nextY>=0){

printCoord(nextX, nextY);

hashBoard[nextX][nextY]=1;

}

//Down

nextX=x; nextY=y+1;

if(nextY<9){

printCoord(nextX, nextY);

hashBoard[nextX][nextY]=1;

}

}

public static void printNonAdjacent()

{

System.out.println("Non Adjacent Points :");

for(int i=0; i<9; i++)

{

for(int j=0; j<9; j++)

{

if(hashBoard[i][j]==0)

printCoord(i, j);

}

}

}

public static void main (String[] args) throws java.lang.Exception

{

for(int i=0; i<9; i++)

{

for(int j=0; j<9; j++)

hashBoard[i][j]=0;

}

Scanner scanner = new Scanner( System.in );

System.out.print( "Type some data for the program: " );

String s = scanner.nextLine();

int x=-1, y=-1; //x->row and t->column

for(int i=0; i<s.length(); i++) {

if(s.charAt(i) == '(')

{

format = 1;

continue;

}

else if(s.charAt(i) == ')')

{

if(format==1)

continue;

else

{

System.out.println("Input format not supported!!!");

System.exit(0);

}

}

else if(s.charAt(i) == ',')

{

if(format == 0)

format = 3;

continue;

}

else if(s.charAt(i) == ' ')

continue;

else if(s.charAt(i)>='a' && s.charAt(i)<='z')

{

if(format == 0 && s.charAt(i+1)==' ')

format = 5;

else

format = 4;

int temp = s.charAt(i);

if(x<0)

x=temp-97;

else

y=temp-97;

}

else if(s.charAt(i)>='0' && s.charAt(i)<='8')

{

int temp = s.charAt(i);

if(x<0)

x=temp-48;

else

y=temp-48;

}

else

{

System.out.println("Input format not supported!!!");

System.exit(0);

}

}

if(format == 0)

format = 2;

printCornerAdjacent(x, y);

printEdgeAdjacent(x, y);

printNonAdjacent();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote