Please provide the code necessary in the fixme sections. thanks Q3Plane(String n
ID: 3731412 • Letter: P
Question
Please provide the code necessary in the fixme sections. thanks
Q3Plane(String name, int speed) {
// FIXME 3a: complete this constructor
}
/** Return the speed of the plane */
int getSpeed() {
return 0; // FIXME 3b: complete this method
}
/**
* Reset the speed of the plane according to the argument speed
* @param speed The new speed of the plane
*/
void resetSpeed(int speed) {
// FIXME 3c: complete this method
}
/**
* Calculate the time to travel the specified distance at the current speed.
* @param distance The distance (in km)
* @return The time to travel the distance (in minutes)
*/
int timeToTravel(int distance) {
return 0; // FIXME 3f: complete this method
}
/**
* Return a string describing the plane and its speed,
* in the format
* "Plane NAME is travelling S km/h"
* where NAME is replaced by the plane's name, and S is replaced by
* the plane's speed.
*
* @return A string describing the plane and its speed
*/
@Override
public String toString() {
return ""; // FIXME 3g: complete this method
}
Explanation / Answer
Q3Plane(String name, int speed) {
this.name=name;
this.speed=speed;
}
int getSpeed() {
return this.speed;
}
void resetSpeed(int speed) {
this.speed=speed;
}
int timeToTravel(int distance) {
int time=(distance/this.speed)*60;
return time;
}
@Override
public String toString() {
return "Plane "+this.name+" is travelling "+this.speed+" km/h";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.