Write a class definition for an abstract class, Vehicle, that contains: a double
ID: 3651396 • Letter: W
Question
Write a class definition for an abstract class, Vehicle, that contains:a double instance variable, maxSpeed
a protected double instance variable, currentSpeed
a constructor accepting a double used to initialize the maxSpeed instance variable
an abstract method, accelerate, that accepts no parameters and returns nothing.
a method getCurrentSpeed that returns the value of currentSpeed
a method getMaxSpeed that returns the value of maxSpeed
a method, pedalToTheMetal, that repeatedly calls accelerate until the speed of the vehicle is equal to maxSpeed. pedalToTheMetal returns nothing.
Explanation / Answer
public class YA110726 { public abstract class Vehicle { double maxSpeed; double currentSpeed; public Vehicle(double aMaxSpeed) { maxSpeed = aMaxSpeed; } abstract void accelerate(); double getCurrentSpeed() { return currentSpeed; } double getMaxSpeed() { return maxSpeed; } void pedalToTheMetal() { while (currentSpeedRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.