Lab 4

public class Lab4
{
	public static void main(String args[])
	{
		Movable transport[] = new Movable[3];
		transport[0] = new Car();
		transport[1] = new Plane();
		transport[2] = new Ship();
		
		for(int i = 0; i < 3; i++)
		{
			transport[i].moveForward();
			transport[i].moveBackward();
			transport[i].stop();
			transport[i].moveLeft();
			transport[i].moveRight();
		}
	}
}
public interface Movable
{
	public void moveForward();
	public void moveBackward();
	public void stop();
	public void moveLeft();
	public void moveRight();
}
public class Car implements Movable
{
	private String car = "Car";
	
	public void moveForward()
	{
		System.out.println(car +" moves forward");
	}
	
	public void moveBackward()
	{
		System.out.println(car +" moves backward");
	}
	
	public void stop()
	{
		System.out.println(car +" has landed");
	}
	
	public void moveLeft()
	{
		System.out.println(car +" turning left");
	}
	
	public void moveRight()
	{
		System.out.println(car +" turning right");
	}
}
public class Plane implements Movable
{
	private String plane = "Plane";
	
	public void moveForward()
	{
		System.out.println(plane +" moves forward");
	}
	
	public void moveBackward()
	{
		System.out.println(plane +" moves backward");
	}
	
	public void stop()
	{
		System.out.println(plane +" has landed");
	}
	
	public void moveLeft()
	{
		System.out.println(plane +" turning left");
	}
	
	public void moveRight()
	{
		System.out.println(plane +" turning right");
	}
}
public class Ship implements Movable
{
	private String ship = "Ship";
	
	public void moveForward()
	{
		System.out.println(ship +" moves forward");
	}
	
	public void moveBackward()
	{
		System.out.println(ship +" moves backward");
	}
	
	public void stop()
	{
		System.out.println(ship +" has landed");
	}
	
	public void moveLeft()
	{
		System.out.println(ship +" turning left");
	}
	
	public void moveRight()
	{
		System.out.println(ship +" turning right");
	}
}

Leave a Reply

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