Question: Implement a class Boat . The Boat class defines three fields (i.e. attributes): name is a variable of type String sailPosition is a variable of
Implement a class Boat. The Boat class defines three fields (i.e. attributes):
- name is a variable of type String
- sailPosition is a variable of type boolean
- speed is a variable of type float.
The Boat class must define:
- Boat constructor
- goFast
- goSlow
- whereIsTheSail.
goFast sets the position of the sail to true and increase the speed of the boat by 10 mph and prints the following text (BlueSea is the boat name):
>> BlueSea is raising the sail at the speed of 10 mph.
goSlow sets the position of the sail to false and decreases the speed of the boat by 5 mph and prints the following text:
>> BlueSea is lowering the sail at the speed of 5 mph.
whereIsTheSail prints the name of the boat and sail is up or sail is down depending on the sail position:
>> BlueSea sail is up.
Note: The boat speed should not exceed 100 mph (max speed is 100 mph) and cannot go below 0 mph.
Define the main class (Main) with a static main method (example provided below). Inside the main method create a new instance of class Boat and then invoke the proper methods as shown below:
public class SimpleBoatApp {
public static void main (String[] args) {
Boat simpleBoat = new Boat("Destinty");
simpleBoat.goFast();
simpleBoat.goSlow();
simpleBoat.whereIsTheSail();
simpleBoat.goFast();
simpleBoat.whereIsTheSail();
simpleBoat.goFast();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
