Question: This is my Location.java, can you create a LocationTester.java, using the info I have provided. Please make sure to include comments, and Javadoc, grade 12
This is my Location.java, can you create a LocationTester.java, using the info I have provided. Please make sure to include comments, and Javadoc, grade 12 coding style, java only. Can you also check if the location.java is written correctly, the coding?
public class Location { public static final int UNGUESSED = 0; public static final int HIT = 1; public static final int MISSED = 2; private boolean ship; private int shipStat;
// Location constructor. public Location() { this.ship = false; this.shipStat = UNGUESSED;
}
// Was this Location a hit? public boolean checkHit() { if(shipStat == HIT) { return true; }
return false; }
// Was this location a miss? public boolean checkMiss() { if(shipStat == MISSED) { return true; }
return false; }
// Was this location unguessed? public boolean isUnguessed() { if(shipStat == UNGUESSED) { return true; }
return false; }
// Mark this location a hit. public void markHit() { shipStat = HIT; }
// Mark this location a miss. public void markMiss() { shipStat = MISSED; }
// Return whether or not this location has a ship. public boolean hasShip() { return ship; }
// Set the value of whether this location has a ship. public void setShip(boolean val) { ship = val; }
// Set the status of this Location. public void setStatus(int status) { shipStat = status; }
// Get the status of this Location. public int getStatus() { return shipStat; } }
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
