Question: Create a Location class for a battleship program. Make sure to include a Location.java, and a LocationTester.java. Include Javadoc, and comments. Grade 12 level coding
Create a Location class for a battleship program. Make sure to include a Location.java, and a LocationTester.java. Include Javadoc, and comments. Grade 12 level coding style using java only. Thank you.
The next class to write is the Location.java file. The Location class stores the information for one grid position.
A location has two defining attributes
1) Is there a ship at this location?
2) What is the status of this location?
The status of this would be whether this position is unguessed, we got a hit, or got a miss.
public static final int UNGUESSED = 0; public static final int HIT = 1; public static final int MISSED = 2;
These are the methods you will need to implement for the Location class.
// Location constructor. public Location() // Was this Location a hit? public boolean checkHit() // Was this location a miss? public boolean checkMiss() // Was this location unguessed? public boolean isUnguessed() // Mark this location a hit. public void markHit() // Mark this location a miss. public void markMiss() // Return whether or not this location has a ship. public boolean hasShip() // Set the value of whether this location has a ship. public void setShip(boolean val) // Set the status of this Location. public void setStatus(int status) // Get the status of this Location. public int getStatus()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
