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...

The WHERE clause, which is optional in a SELECT statement, narrows the query results by specifying which ________ in the table will be returned in the dataset

Fill in the blank(s) with correct word

Computer Science & Information Technology

Formatting temporarily hides rows that do not meet the criteria

Indicate whether the statement is true or false

Computer Science & Information Technology

Tracing formulas draw ________ from a formula to cells that supply source data and to formulas that use the result of a formula

Fill in the blank(s) with correct word

Computer Science & Information Technology

Which of the following could be used as hard drive controllers? (Choose all that apply.)

ATA PATA SATA SCSI

Computer Science & Information Technology