Lab # 4

Description

The main objective of this lab was to create a MobileDevice inheritance hierarchy using private instance variables. Therefore, we had to create three different layers each one using different classes and finally, using a client code to run the whole program.  All Classes must follow this hierarchy;

  1. Mobile Device
  2. SmarthPhone
  3. Android, iPhone, Windows Phone

Codes 

MobileDevice

//Tax, Julio
package Lab4;

public class MobileDevice {

	private String deviceType = "Mobile Device";

	public void setDeviceType()
	{

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

SmarthPhone

 // Tax, Julio
package Lab4;

public class SmartPhone extends MobileDevice {
	private String SmartPhone = "Mobile Device ===== SmartPhone";
	public void setDeviceType() 
	{
		this.SmartPhone= "SmartPhone";
	}
public String getDeviceType()
{
	return this.SmartPhone;
}
}

Android

 // Tax, Julio
package Lab4;

public class Android extends SmartPhone 
{
	private String Android= "Mobile Device === SmartPhone === Android";
	public void setDeviceType()
	{
		this.Android = "Android";

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

iPhone

 // Tax, Julio

package Lab4;

public class iPhone extends SmartPhone
{
	private String iPhone= "Mobile Device === SmartPhone === iPhone";
	public void setDeviceType() 
	{
		this.iPhone = "iPhone";

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

Windows Phone

// Tax, Julio
package Lab4;

public class WindowsPhone extends SmartPhone
{
	private String WindowsPhone="Mobile Device === SmartPhone === Windows Phone";
	public void setDeviceType()
	{
		this.WindowsPhone = "WindowsPhone";
	}
	public String getDeviceType()
	{
		return this.WindowsPhone;
	}
}

Screenshots

 

Lab # 4 – Tax, Julio