Question
I have a a java project that I had to build from scratch. Its main purpous was to be a battlship program. where a character
I have a a java project that I had to build from scratch. Its main purpous was to be a battlship program. where a character array marked by O's is the board. I was to generate three sets of random numbers to be the computers ships and put them ito an array list. withwich i copared them with an equals to method agains user inputs. My code was fine up until the equals method but then I completely broke it.
import java.util.Random; import java.util.ArrayList; import java.util.Scanner;
public class Location { // attributes private int row; private int column; //constructor public Location(int row, int column) { this.row = row; this.column = column; } //- a copy constructor public Location(Location ship){ this(ship.row, ship.location); } // getter and setter public void setRow(int row){ this.row = row; } public void setColumn(int column){ this.column = column; } public int getRow(){ return row; } public int getColumn(){ return column; } public class Driver { public static void main(String[] args){ { final int All_Ships = 3; // Creation of the gameboard char[][] gameboard = new char [5][5]; char[][] gameboard = {O,O,O,O,O, O,O,O,O,O, O,O,O,O,O, O,O,O,O,O, O,O,O,O,O,}; } { // To print the game board columns by row for(char c=0; c ArrayLists int turnstaken = t; int shipsleft = locationsList.size(); for (i = 0; i < 4; t++) { int row = sc.nextInt(); int column = sc.nextInt(); System.out.println("Turn" + t + "of 4"); System.out.println("Guess a row:" + row); System.out.println("Guess a column:" + column); // creating an equals too method for co-ordinate comparison { for(char c=0; c
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started