Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java language 3 Consider a class MotorBoat that represents motorboats. A motorbo

ID: 3880618 • Letter: J

Question

Java language 3 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 If the boat has efficiency e, the amount of fuel used when traveling at a speed s for time t is e × s× t. The distance traveled in that time is s 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.

Explanation / Answer

public class MotorBoat{

private static float CAPACITY_FUEL_TANK;

private static int MAX_SPEED;

private float currentFuel;

private int currentSpeed;

private float efficiency;

private int distance;

public MotorBoat(float capacity,int maxSpeed){

CAPACITY_FUEL_TANK = capacity;

MAX_SPEED = maxSpeed;

}

public MotorBoat(float capacity,int maxSpeed, float efficiency){

CAPACITY_FUEL_TANK = capacity;

MAX_SPEED = maxSpeed;

this.efficiency = efficiency;

}

public void setEfficiency(float efficiency){

this.efficiency = efficiency;

}

public String changeSpeed(int newSpeed){

if(newSpeed > MAX_SPEED){

return "newSpeed is greater than the MAX-SPEED of the MotorBoat";

}

currentSpeed = newSpeed;

if(newSpeed == 0){

return "Boat is not moving now";

}

return "Speed changed successfully";

}

public String operateBoat(int time){

if(currentSpeed == 0){

distance = 0;

return "Boat is not moving right now";

}

float fuelUsed = efficiency * currentSpeed * currentSpeed * time;

if(fuelUsed > currentFuel){

return "Boat does not have sufficient fuel to be operated";

}

distance = distance + (currentSpeed * time);

currentFuel = currentFuel - fuelUsed;

return "Boat got operated for the given time";

}

public String refuelBoat(float fuel){

float newFuel = currentFuel+fuel;

if(newFuel > CAPACITY_FUEL_TANK){

return "amount of fuel is getting greater than capacity of fuel tank";

}

currentFuel = newFuel;

return "refueled successfully";

}

public float getAmountFuel(){

return currentFuel;

}

public int getDistanceTravelled(){

return distance;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote