LAB 3 – Inheritance

 

Lab Report 3 – Description

For this lab we created a class name MobileDevice with a private field String devicetype that equaled to a string “Mobile Device.  We were to either create setter getter methods or just create a getmethod within itself and return this devicetype.  The second part of this lab was to create another class called SmartPhone that extends to MobileDevice and need to also consist of a private field string devicetype that initialized a string “Smart Phone”.  For the third part of this lab, we created three more classes (Android, iPhone, and WindowsPhone), and repeated the same steps as mobiledevice and smart phone class.  That is where we needed to create a private field String devicetype that initialized their perspective class, such as android, iphone, windowsphone.   This lab allowed you to understand how the inheritance class, override, and get methods worked simultaneously with one another.

Code:

package LAB_3;

public class mobileDevice {
	private String deviceType = "Mobile Device";

	public void setdeviceType()
	{
		return;
	}

	public String getdeviceType()
	{
		return deviceType;
	}

}

package LAB_3;

public class smartPhone extends mobileDevice {
	private String deviceType = "Smart Phone";

	public String getdeviceType()
	{
		deviceType = super.getdeviceType()+ " => " +deviceType;
		return deviceType;
	}
}

package LAB_3;

public class iPhone extends smartPhone {
	private String deviceType = "iPhone";

	public String getdeviceType()
	{
		deviceType = super.getdeviceType()+ " => " +deviceType;
		return deviceType;
	}
}

package LAB_3;

public class android extends smartPhone {
	private String deviceType = "Android";

	public String getdeviceType()
	{
		deviceType = super.getdeviceType()+ " => " +deviceType;
		return deviceType;
	}
}

package LAB_3;

public class windowsPhone extends smartPhone {
	private String deviceType = "Windows Phone";

	public String getdeviceType()
	{
		deviceType = super.getdeviceType()+ " => " +deviceType;
		return deviceType;
	}
}

package LAB_3;

public class MobileDeviceClient {
	String Introduction;
	public MobileDeviceClient (String Program)
	{
		Introduction = Program;
	}

	public String getWELCOME()
	{
		return Introduction;
	}

	public void MSGDISPLAY()
	{
		System.out.printf("Welcome to Washington Sarmiento's Third Program\n%s!\n\n", getWELCOME());
	}

	public static void main(String[] args) {
		MobileDeviceClient prgMessage = new MobileDeviceClient("CET3640f2013 LAB 3: Inheritance");
		prgMessage.MSGDISPLAY();
		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-11-11 at 12.32.51 AM

Leave a Reply

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