lab5

Lab Description:

In this lab we are to create a abstract superclass name MobileDevice. Than two subclass SmartPhone and Tablet by using the keyword extends that inherit the superclass that is MobileDevice. Than two more subclass Android and WindowsPhone that inherit from SmartPhone. Than two more subclass iPad and KindleFire that inherit from Tablet. Using the set and getter methods. Than use the array to call the system out .

CODE

package lab5;

public class DeviceApp {

	/**
	 * @param args
	 */
	public static void main (String[] args) {
		// TODO Auto-generated method stub
		MobileDevice[] mobileDevices = new MobileDevice[6];
		mobileDevices[0]	=	new Tablet();
		mobileDevices[1]	=	new iPad();
		mobileDevices[2]	=	new KindleFire();
		mobileDevices[3]	=	new SmartPhone();
		mobileDevices[4]	=	new Android();
		mobileDevices[5]	=	new WindowsPhone();

		for (int j = 0; j < 6; j++) {
			System.out.println("This device is: " + mobileDevices[j].getDeviceType());
		}

	}

}

package lab5;

public abstract class MobileDevice {

	private String deviceType = "Mobile Device";

	public abstract void setDeviceType();

	public String getDeviceType() {
		// TODO Auto-generated method stub
		return deviceType;
	}
	@Override
	public String toString() {
		return deviceType;
	}

}

 package lab5;

public class Tablet extends MobileDevice {

	private String deviceType;

	public Tablet(){
		deviceType= "Tablet";
	}

	@Override
	public String getDeviceType() {
		return deviceType;
	}

	@Override
	public void setDeviceType() {
		// TODO Auto-generated method stub
		deviceType = "Tablet";
	}

	@Override
	public String toString() {
		return deviceType;
	}

}

package lab5;

public class iPad extends Tablet{

	private String deviceType;

	public iPad() {
		deviceType = "iPad";

	}

	@Override
	public String getDeviceType() {
		return deviceType;
	}

	@Override
	public void setDeviceType() {
		// TODO Auto-generated method stub
		deviceType = "iPad";
	}

	@Override
	public String toString() {
		return deviceType;
	}
}

package lab5;

public class KindleFire extends Tablet{

	private String deviceType ;

	public KindleFire(){
		deviceType= "KindleFire";
	}

	@Override
	public String getDeviceType() {
		deviceType = "KindleFire";
		return deviceType;
	}

	@Override
	public void setDeviceType() {
		// TODO Auto-generated method stub
		deviceType = "KindleFire";
	}

	@Override
	public String toString() {
		return deviceType;
	}
}

package lab5;

public class SmartPhone extends MobileDevice{

	private String deviceType ;

	public SmartPhone(){
		deviceType= "SmartPhone";
	}

	@Override
	public String getDeviceType() {
		return deviceType;
	}

	@Override
	public void setDeviceType() {
		// TODO Auto-generated method stub
		deviceType = "SmartPhone";
	}

	@Override
	public String toString() {
		return deviceType;
	}

}

package lab5;

public class Android extends SmartPhone {

	private String deviceType ;

	public Android(){
		deviceType= "Android";
	}

	@Override
	public String getDeviceType() {
		deviceType = "Android";
		return deviceType;
	}

	@Override
	public void setDeviceType() {
		// TODO Auto-generated method stub
		deviceType = "Android";
	}

	@Override
	public String toString() {
		return deviceType;
	}
}

package lab5;

public class WindowsPhone extends SmartPhone {

	private String deviceType ;

	public WindowsPhone(){
		deviceType= "WindowsPhone";
	}

	@Override
	public String getDeviceType() {
		deviceType = "WindowsPhone";
		return deviceType;
	}

	@Override
	public void setDeviceType() {
		// TODO Auto-generated method stub
		deviceType = "WindowsPhone";
	}

	@Override
	public String toString() {
		return deviceType;
	}
}

Screen shot: