Objective:
This lab was similar to the previous lab where you had to create classes, in this case we have to create three classes called Car, Plane, and Ships. Then apply it to the interface movable object once this classes are created.
Code:
package lab6; public interface Movable { public void moveForward(); public void moveBackward(); public void stop(); public void moveLeft(); public void moveRight(); } package lab6; public class MovableApp { public static void main(String[] args) { Movable[] mynewMovable = new Movable[3]; mynewMovable[0] = new Car(); mynewMovable[1] = new Plane(); mynewMovable[2] = new Ship(); for(Movable m: mynewMovable){ m.moveForward(); m.moveBackward(); m.stop(); m.moveLeft(); m.moveRight(); System.out.println(""); } } } package lab6; public class Plane implements Movable { public static void main(String[] args) { } public void moveForward() { System.out.println("Plane flying forward"); } public void moveBackward() { System.out.println("Plane taxing backward"); } public void stop() { System.out.println("Plane landed"); } public void moveLeft() { System.out.println("Plane flying left"); } public void moveRight() { System.out.println("Plane flying right"); } } package lab6; public class Car implements Movable { public static void main(String[] args) { } public void moveForward() { System.out.println("Car drives forward"); } public void moveBackward() { System.out.println("Car drives backward"); } public void stop() { System.out.println("Car parked"); } public void moveLeft() { System.out.println("Car turn left"); } public void moveRight() { System.out.println("Car turns right"); } } package lab6; public class Ship implements Movable { public static void main(String[] args) { } public void moveForward() { System.out.println("Ship navigates forward"); } public void moveBackward() { System.out.println("Ship navigates backward"); } public void stop() { System.out.println("Ship docked"); } public void moveLeft() { System.out.println("Ship navigates left"); } public void moveRight() { System.out.println("Ship navigates right"); } }