Lab 4

Lab Description:

This lab was an intro into how to use Inheritance hierarchy. We crated Mobile Device with subclass SmartPhone. Under SmartPhone we had subclasses called Android, iPhone, and WindowsPhone. One of the new comands that we used in this lab was extend this help the program to go from one part to another to inherit. The code for MobileDeviceClient was given to us in the lab from the professor.

 

Source Code:
Mobile Device Client

package MobileDevice;

public class MobileDeviceClient {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		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());
	}
}

Mobile Device

package MobileDevice;

public class MobileDevice {
	private String deviceType;

	public MobileDevice() {

		deviceType = "Mobile Device";
		// TODO Auto-generated constructor stub
	}

	public String getDeviceType() {
		return deviceType;
	}

	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}

}

Smart Phone

package MobileDevice;

public class SmartPhone extends MobileDevice{
	private String deviceType;
	public SmartPhone() {
		deviceType = "SmartPhone";
		// TODO Auto-generated constructor stub
	}
	public String getDeviceType() {
		return deviceType;
	}
	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}
}

iPhone

package MobileDevice;

public class iPhone extends SmartPhone{
	private String deviceType;

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

	public String getDeviceType() {
		return deviceType = "Mobile Device -> Smart Phone -> iPhone";
	}
}

Android

package MobileDevice;

public class Android extends SmartPhone{
	private String deviceType;

	public Android() {
		deviceType = "Android";

	}

	public String getDeviceType () {
		return deviceType = "Mobile Device -> Smart Phone -> Android";
	}
}

Windows Phone

package MobileDevice;

public class WindowsPhone extends SmartPhone {
	private String deviceType;

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

	}

	@Override
	public String getDeviceType() {
		return deviceType = "Mobile Device -> Smart Phone -> Windows Phone";
	}
}

Screen Shot: