Objective:
The goal for this lab is to create 3 classes which they are called Car(), Planes(), Ships() and for each class we are suppose to implement each class, and then we have to create a class that can process an array of Movable by calling classes.
Code:
package lab6; public class MovableApp { public static void main(String[] args) { Movable[] myMovables = new Movable[3]; myMovables[0] = new car(); myMovables[1] = new planes(); myMovables[2] = new ships(); for(Movable m: myMovables){ m.moveForward(); m.moveBackward(); m.stop(); m.moveLeft(); m.moveRight(); System.out.println("_____________________"); } } }
package lab6; public interface Movable { public void moveForward(); public void moveBackward(); public void stop(); public void moveLeft(); public void moveRight(); }
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 turns left"); } public void moveRight() { System.out.println("Car turns right"); } }
package lab6; public class planes implements Movable { public static void main(String[] args) { } public void moveForward() { System.out.println("Planes Fly Foward"); } public void moveBackward() { System.out.println("Planes Fly backwards"); } public void stop() { System.out.println("Planes parked"); } public void moveLeft() { System.out.println("Planes turn left"); } public void moveRight() { System.out.println("Planes turn right"); } }
package lab6; public class ships implements Movable { public static void main(String[] args) { } public void moveForward() { System.out.println("ships navegates Foward"); } public void moveBackward() { System.out.println("ships navegates backwards"); } public void stop() { System.out.println("ships Stop"); } public void moveLeft() { System.out.println("ships turn left"); } public void moveRight() { System.out.println("ships turn right"); } }