Lab 3

Description

In this lab, I developed five classes. The first class I developed is called “Mobile Device”. This class would a super class, otherwise known as,a grandparent for the next four subclasses . The next class developed is called Smart Phone. The Smart Phone would inherit the same capabilities as Mobile Device. This class can be called a parent because three other classes would inherit the capabilities from the smart phone. The next three classes are iphone, andriod, and windows phone. These three inherits the capabilities as the smart phone. Now, when I first made the mobile device, I made a private field called “devicetype” which will hold all the methods and implementations of Mobile Device. Next, I used a set and get method to set all the data that would be stored in devicetype, and get the results from whatever method was used in the “setdevicetype”. However, for this lab, there wasn’t really any implementations done on this device type. Next, I override the gettermethod by returning the string within the class smart phone. This help me grab whatever results from the mobile device class with the help of super. Super allows the class to invoke whatever argument in the superclass, in the case, the subclass constructor didn’t invoke the super class constructor. In this lab, super allowed me to grab whatever constructor was in mobile device for subclass, and identify what kind of device it is. I did this for each class iphone, andriod, and windows phone.

Source Code

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

		public String setdeviceType()
		{ 
			return deviceType;
}

	public String getdeviceType(){

		return deviceType;
	}
		}
public class SmartPhone extends MobileDevice {
	private String deviceType ="Smart Phone";
	public String getdeviceType(){

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

public class andriod extends SmartPhone {
	private String deviceType ="andriod";
	public String getdeviceType(){

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

public class iPhone extends SmartPhone {
	private String deviceType ="iPhone";
	public String getdeviceType(){

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

}
public class WindowsPhone extends SmartPhone {
	private String deviceType ="Windows Phone";
	public String getdeviceType(){

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

}

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();
		andriod myandriod = new andriod();
		WindowsPhone myWindowsPhone = new WindowsPhone();
		System.out.println(myMobileDevice.getdeviceType());
		System.out.println(mySmartPhone.getdeviceType());
		System.out.println(myiPhone.getdeviceType());		
		System.out.println(myandriod.getdeviceType());
		System.out.println(myWindowsPhone.getdeviceType());
	}

}

ScreenShot
java p

Leave a Reply

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