Coding in Java
Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for all methods should print simple messages to the screen using System.out.println(). Add an integer speed variable that is changed using ChangeSpeed method. ChangeSpeed adds 5 to the speed each time it is called. Create a default constructor that sets the initial speed to 0. Don't create other constructors or any setter/getter methods.
// code from Q1:
interface Vehicle {
void Start();
void Stop();
void ChangeSpeed();
}
//Airplane.java public class Airplane implements Vehicle{ int speed; public Airplane() { this.speed = 0; } public int getSpeed() { return speed; } public void setSpeed(int speed) { this.speed = speed; } public void Start() { System.out.println("Airplane Started"); } public void Stop() { System.out.println("Airplane Stopped"); } public void ChangeSpeed() { speed += 5; } }
Get Answers For Free
Most questions answered within 1 hours.