It\'s the end of the semester and I have a big project to do. It\'s a multi-clas
ID: 3824360 • Letter: I
Question
It's the end of the semester and I have a big project to do. It's a multi-class Battleship game. However, I seem to be having problems with the BattleBoard.java class, more specifically the public boolean isShipSunk(int shipIndex), the public ArrayList getAllSunkenShips(), and the public HitStatus getHitStatus(int row, int col) methods. I simply have no idea what they need to look like. Here are the instructions
public boolean isShipSunk(int shipIndex): returns true if the ship at the specified index in the array has been sunk by enemy fire.
public ArrayList<Ship> getAllSunkenShips(): returns an ArrayList of Ships that have been sunk by enemy fire.
public HitStatus getHitStatus(int row, int col): returns the HitStatus of the Square located at the specified row and column. Throw an IllegalArgumentException if row < 0, col < 0, row >= number of rows, or col >= number of columns.
For reference, this is the HitStatus enum from my Square class
public enum HitStatus {
HIT, //hit and occupied
MISSED, //hit and unoccupied
NOT_YET_HIT// not yet hit
}
I need to know exactly what these methods are supposed to look like
Here is a link to my code if you need to see it
https://drive.google.com/file/d/0B1nKgE0afMEmMGxuNmlUdE04WHM/view?usp=sharing
Explanation / Answer
Please find the function definations as below:
public boolean isShipSunk(int shipIndex)
{
if(ships[shipIndex].isSunk())
return True;
else
return False;
}
public ArrayList<Ship> getAllSunkenShips()
{
ArrayList<Ship> sunkShip;
for(int i = 0; i < numberOfShips; i++)
{
if(ships[i].isSunk())
sunkShip.add(ships[i]);
}
return sunkShip();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.