Lab 4

Description
This Lab was the sum of a lot of topics learned in this course. it was very interesting to see how everything functions and how the change of one word makes a difference. From the lectures I was able to understand what the implications meant when Professor Reyes was explaining yet in the lab, it should me that it wasn’t as simple as the professor made it appear. but this lab really help me to put to practice what the professor said. im starting to enjoy working with Java.

Codes

package lab4;

public class Movables {
	public static void main(String[] args) {
		Movable[] myMovable = new Movable[3];
		myMovable[0] = new Plane();
		myMovable[1] = new Car();
		myMovable[2] = new Ship();

		for (Movable m: myMovable){
			m.moveForward();
			m.moveBackward();
			m.stop();
			m.moveLeft();
			m.moveRight();
			System.out.println("-------------------------");
		}
	}
}
package lab4;

public interface Movable {
	public void moveForward();
	public void moveBackward();
	public void stop();
	public void moveLeft();
	public void moveRight();

}
package lab4;

public class Plane implements Movable{

	@Override
	public void moveForward() {
		System.out.println("Plane flying forward");

	}

	@Override
	public void moveBackward() {
		System.out.println("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");
	}


}
package lab4;

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 turn right");


	}

}
package lab4;

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");
	}

}

Screenshots
1

2

4

3

5

6

Leave a Reply

Your email address will not be published. Required fields are marked *