LAB 4

Objective:

In this laboratory experiment we had to create different classes that will follow the diagram below. However it is not as simple as it looks. In order to acomplish such task, we had to use java cunstructors, override , the getter method, which helped us to set the following hierarchy :

 

SOURCE 1 (MobileDevice)

public class MobileDevice {	
	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(mySmartPhone.getDeviceType());
		System.out.println(myiPhone.getDeviceType());		
		System.out.println(myAndroid.getDeviceType());
		System.out.println(myWindowsPhone.getDeviceType());
	}
}

SOURCE 2 (SmartPhone )

public class SmartPhone extends MobileDevice {

	private String SmartPhone = "SmartPhone";

	public void setDeviceType (){
		this.SmartPhone = "SmartPhone";

	}

	public String getDeviceType() {
		return this.SmartPhone= "SmartPhone";

	}
	public String toString () {
		return this.SmartPhone ;

	}
}

SOURCE 3  (Android)

public class Android extends MobileDevice {

	private String Android = "Android";

	public void setDeviceType (){
		this.Android = "Android";

	}

	public String getDeviceType() {
		return this.Android= "Android";

	}
	public String toString () {
		return this.Android ;

	}
}

SOURCE 4  (iPhone)

 
public class iphone extends MobileDevice {

	private String iphone = "iphone";

	public void setDeviceType (){
		this.iphone = "iphone";

	}

	public String getDeviceType() {
		return this.iphone= "iphone";

	}
	public String toString () {
		return this.iphone ;

	}
}

SOURCE 5  (Windows Mobile)

public class WindowsPhone extends MobileDevice {

	private String WindowsPhone = "WindowsPhone";

	public void setDeviceType () {
		this.WindowsPhone = "WindowsPhone";

	}
	public String getDeviceType (){
		return this.WindowsPhone;

	}
	public String toString (){
	return this.WindowsPhone;

	}

}

ScreenShot