I decided to test my one years worth of java programming training I have learned this year in high school.
I found this assignment online and started following it.
I am having trouble with Part 3 (attacking ships)
this is the description in the class given of the method:
/**
* Attacks the grid cell at the specified row and column.
* If the grid cell contains:
* - SHIP: the value of the cell is set to HIT
* - HIT: the value of the cell does not change
* Otherwise, the value of the cell is set to MISS.
*
* This method returns true if the attack resulted in a ship being hit,
* and false otherwise.
*
* Note: this method also returns true if a cell that has already
* been hit is attacked.
*
* @param row the row of the cell to attack
* @param col the column of the cell to attack
*
* @return true if the attack results in a ship being hit (even
* if the ship at that cell has already been hit),
* false otherwise
*/
public boolean attack(int row, int col)
{
//FILL IN THIS CODE
return false;
}
There is a getCell method that returns the value in the given row, column of the 2d array. (I assume i will need this to check the value before making it a HIT)
What I have the question about is, how do I set up the boolean expression. My class didn't cover boolean true/false statements well.
Whats the best way to set up this attack method where I fill in the code?
Thanks for any help given! Let me know if you need any of my code so far.
Jon