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 classBoat. TheBoatclass defines three fields (i.e. attributes):
- nameis a variable of type String
- sailPosition is a variable of type boolean
- speed is a variable of type float.
TheBoatclass must define:
- Boat constructor
- goFast
- goSlow
- whereIsTheSail.
goFastsets the position of the sail totrueand increase the speed of the boat by 10 mph and printsthe following text (BlueSea is theboat name):
>> BlueSea is raising the sail at the speed of 10 mph.
goSlowsets the position of the sail tofalseand decreases the speed of the boat by 5 mph and printsthe following text:
>> BlueSea is lowering the sail at the speed of 5 mph.
whereIsTheSailprints 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 themain 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started