If the boat has efficiency e, the amount of fuel used when traveling at a speed s for time t is . The distance traveled in that time is .

Consider a class MotorBoat that represents motorboats. A motorboat has attributes for
• The capacity of the fuel tank
• The amount of fuel in the tank
• The maximum speed of the boat
• The current speed of the boat
• The efficiency of the boat’s motor
• The distance traveled
The class has methods to
• Change the speed of the boat
• Operate the boat for an amount of time at the current speed
• Refuel the boat with some amount of fuel
• Return the amount of fuel in the tank
• Return the distance traveled so far

a. Write a method heading for each method.
b. Write preconditions and postconditions for each method.
c. Write some Java statements that test the class.
d. Implement the class.

a) ```
public void changeSpeed(double newSpeed)
public void operateForTime(double time)
public void refuelBoat(double amount)
public double fuelRemaining()
public double distance()
```

b)
public void changeSpeed(double newSpeed)
Precondition: newSpeed is positive.
Postcondition: The speed of the motor boat has been set to the minimum of newSpeed and the maximum speed.

public void operateForTime(double time)
Precondition: time is positive.
Postcondition: The motor boat operates for the given amount of time or until it runs out of fuel. The fuel and distance traveled will be updated appropriately.

public void refuelBoat(double amount)
Precondition: amount is positive.
Postcondition: The fuel in the motor boat will be set to the minimum of maximum fuel capacity and current fuel plus the given amount.

public double fuelRemaining()
Precondition: none.
Postcondition: The amount fuel in the boat was returned.

public double distance()
Precondition: none.
Postcondition: The distance traveled in boat was returned.

c&d)
See the code in MotorBoat.java.

Computer Science & Information Technology

You might also like to view...

On-premises

What will be an ideal response?

Computer Science & Information Technology

The terminal I/O user interface is familiar to all PC users.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology