Lab 3

Lab Description:

This lab is about inheritance. To begin, I create five classes as instructed on the lab sheet. The second class inherits the first class and the last three classes inherit the second class. Finally, copy the client class on the lab sheet that suppose to able to run if the classes I created followed the instruction.

Code:

//Name: Guan Hong Chen
//Date: Oct. 21 2013
//CET 3640 Fall 2013
//MobileDevice.java

public class MobileDevice 
{
	private String deviceType;

	public MobileDevice()
	{
		deviceType = "Mobile Device";
	}

	public void setDeviceType(String Type)
	{
		deviceType = Type;
	}

	public String getDeviceType()
	{
		return deviceType;
	}

}
//Name: Guan Hong Chen
//Date: Oct. 21 2013
//CET 3640 Fall 2013
//SmartPhone.java

public class SmartPhone extends MobileDevice 
{
	private String deviceType;

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

	public String getDeviceType() 
	{
		return super.getDeviceType()  + " -> " + deviceType;
	}

}
//Name: Guan Hong Chen
//Date: Oct. 21 2013
//CET 3640 Fall 2013
//Android.java

public class Android extends SmartPhone 
{
	private String deviceType;

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

	public String getDeviceType() 
	{
		return super.getDeviceType() + " -> " + deviceType;
	}

}
//Name: Guan Hong Chen
//Date: Oct. 21 2013
//CET 3640 Fall 2013
//iPhone.java

public class iPhone extends SmartPhone 
{
	private String deviceType;

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

	public String getDeviceType() 
	{
		return super.getDeviceType() + " -> " + deviceType;
	}

}
//Name: Guan Hong Chen
//Date: Oct. 21 2013
//CET 3640 Fall 2013
//WindowsPhone.java

public class WindowsPhone extends SmartPhone 
{
	private String deviceType;

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

	public String getDeviceType() 
	{
		return super.getDeviceType() + " -> " + deviceType;
	}

}
//Name: Guan Hong Chen
//Date: Oct. 21 2013
//CET 3640 Fall 2013
//MobileDeviceClient.java

public class MobileDeviceClient {

	public static void main(String[] args) 
	{
		MobileDevice myMobileDevice = new MobileDevice();
		SmartPhone mySmartPhone = new SmartPhone();
		iPhone myiPhone = new iPhone();
		Android myAndroid = new Android();
		WindowsPhone myWindowsPhone = new WindowsPhone();
		System.out.println(myMobileDevice.getDeviceType());
		System.out.println(mySmartPhone.getDeviceType());
		System.out.println(myiPhone.getDeviceType());		
		System.out.println(myAndroid.getDeviceType());
		System.out.println(myWindowsPhone.getDeviceType());

	}

}

Screenshots:

Screen Shot 2013-10-21 at 2.22.46 PM

Leave a Reply

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