Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Please edit the code as the instruction says for battle boat java program. 2 Battleboat Class A Battleboat object will have the following attributes:

JAVA

Please edit the code as the instruction says for battle boat java program.

2 Battleboat Class A Battleboat object will have the following attributes: private int size: indicates the number of Cell objects a Battleboat spans. Default this value to 3 private boolean orientation: indicates the orientation of the Battleboat (horizontal or vertical, can be randomly decided) private Cell[] spaces: array of the Cell objects associated with the Battleboat And the following functions: public boolean get_orientation(): getter method for orientation attribute public int get_size(): getter method for size attribute public Cell[] get_spaces(): getter method for spaces attribute public Battleboat(): Battleboat class constructor Hint: To generate random numbers, the Math.random() method can be used. However, this method returns a double in the range 0 to 1. We will need to scale this and then round it to a whole. To do this, use the Math.floor(x) function, which takes a double x and rounds it down to the nearest integer. For example, Math.floor(2.9) is 2.

public class Battleboat {

private int size;

private boolean orientation; // false <-> horizontal, true <-> vertical

private Cell[] spaces;

// TODO: randomly set the orientation of the boat

// TODO: set size of the boat (default to 3-cells long)

// TODO: declare the Cell objects associated with each boat

public Battleboat(){

}

// TODO:

public boolean get_orientation(){

return orientation;

}

// TODO:

public int get_size(){

}

// TODO:

public Cell[] get_spaces(){

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions