Question
use Java please. You want to simulate different MotorBoats. Write a class MotorBoat that represents motorboats. A MotorBoat has the following private attributes: The name
use Java please.
You want to simulate different MotorBoats. Write a class MotorBoat that represents motorboats. A MotorBoat has the following private attributes:
The name of the MotorBoat (String)
The capacity of the fuel tank (liters)
The current amount of fuel in the tank (liters)
The maximum speed of the boat (kmph)
The current speed of the boat (kmph)
The rate of fuel consumption (liters/km)
The distance traveled (km)
and the following methods:
Constructor that sets the name, capacity, fuel in the tank, max speed and fuel consumption to the given values and current speed to zero.
Get and set methods
Method called changeSpeed to change the speed of the boat (the method should accept the change which is a positive or negative number and change the current speed. If the change is greater than its max speed, it should set the current speed to max speed).
Method called cruise that will operate the boat for an amount of time in minutes at the current speed (this method should set the distance traveled and reduce the amount of fuel in the tank by the appropriate amount).
Method called increaseFuel that will refuel the boat with some amount of fuel (if the total amount of fuel is greater than the capacity, set it to the capacity).
Method called fasterBoat which will compare this MotorBoat with another MotorBoat and return true if this MotorBoat has a higher max speed.
Method called equals which will compare this MotorBoat with another MotorBoat to see if it the same type of boat in terms of its max speed, capacity of fuel tank, and the rate of fuel consumption. If these attributes are the same, then the method will return true.
A toString method that prints out the attributes of the motorboat: name, current speed, distance traveled so far and the amount of fuel left in the tank.
Note: If the rate of fuel consumption is r and the distance traveled is d, then the amount of fuel remaining in the tank = fuel in tank r*d
Write a tester program that creates two motorboat objects and test them using various methods. For example, here is one test case: create a motorboat named Speedy with capacity 100 liters, fuel in tank 50 liters, max. speed 100 kmph, rate of fuel consumption 1. Set its speed to 25 kmph and operate it for 30 minutes. Print the boat's current speed, distance driven and the fuel remaining in the tank (toString). Then increase the speed by 25, and operate it for 30 minutes. Print the boat.
Then create another motorboat called Flippy with capacity 90 liters, fuel in tank 45 liters, max speed of 120 kmph, rate of feul consumption .75. Set speed to 45kmph and operate it for 20 minutes. Print the boat. Refuel with 50 liters, increase speed by 15 kmph and operate for 30 minutes. Print the boat.
Then print out the faster boat and if the two boats are the same or not.
Your output should be:
Name: Speedy
Current Speed: 25.0 kmph
Distance Driven: 12.5 km
Fuel in Tank: 37.5 litres
Name: Speedy
Current Speed: 50.0 kmph
Distance Driven: 25.0 km
Fuel in Tank: 12.5 litres
Name: Flippy
Current Speed: 45.0 kmph
Distance Driven: 15.0 km
Fuel in Tank: 33.75 litres
Name: Flippy
Current Speed: 105.0 kmph
Distance Driven: 52.5 km
Fuel in Tank: 44.375 litres
Fastest Boat: Flippy
Speedy and Flippy are not the same boat
Test your program to check for other cases as well. (at least three test cases).
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