//Kenny Cruz
//CET 3640
//Lab 4
public interface Movable {
public void moveForward();
public void moveBackward();
public void stop();
public void moveLeft();
public void moveRight();
}
b) Plane.java
public class Plane implements Movable{
@Override
public void moveForward() {
System.out.println( “The Plane is flying forward”);
}
@Override
public void moveBackward() {
System.out.println( “The Plane taxiing backward”);
}
@Override
public void stop() {
System.out.println( “Plane landed”);
}
@Override
public void moveLeft() {
System.out.println( “Plane flying left”);
}
@Override
public void moveRight() {
System.out.println( “Plane flying right”);
}
}
Car.java
public class Car implements Movable{
@Override
public void moveForward() {
System.out.println( “Car drives forward”);
}
@Override
public void moveBackward() {
System.out.println(“Car drives backward”);
}
@Override
public void stop() {
System.out.println(“Car parked”);
}
@Override
public void moveLeft() {
System.out.println(“Car turns left”);
}
@Override
public void moveRight() {
System.out.println(“Car turns right”);
}
}
Ship.java
public class Ship implements Movable{
@Override
public void moveForward() {
System.out.println(“Ship navigates forward”);
}
@Override
public void moveBackward() {
System.out.println(“Ship navigates backward”);
}
@Override
public void stop() {
System.out.println(“Ship docked”);
}
@Override
public void moveLeft() {
System.out.println(“Ship navigates left”);
}
@Override
public void moveRight() {
System.out.println(“Ship navigates right”);
}
}
InterfaceTest.java
public class InterfaceTest{
public static void main(String[] args){
Movable[] movable = new Movable[3];
movable[0] = new Plane();
movable[1] = new Car();
movable[2] = new Ship();
System.out.println(“———————“);
for (Movable now : movable)
{
now.moveForward();
now.moveBackward();
now.stop();
now.moveLeft();
now.moveRight();
System.out.println(“———————“);
}
}
}