Lab 3

Description:

In this java lab, I will be working on a Java programming technique call inheritance. When creating a new class, which is a superclass it can be created so that it should inherit the members of an existing class, which are called subclass, It is formed like a hierarchy system. For this lab I had to create a hierarchy is-a relationship with phone objects. MoblieDevice is the superclass, Smart Phone, IPhone, Android and Windows Phone are all subclasses. I had to first create a package and then create seperable classes all under one package to execute the program using a test class which is MoblieDeviceClient. The string deviceType is set to private, so the user will have to access deviceType by using the set and get methods. Set is to call the private string and then get is to retrieve data into public from the private. For IPhone, Android and Windows Phone, I had to use the keyword extends to push the data of Smart Phone into the subclasses. Then the main method is used in MoblieDeviceClient to run all the classes created in the package to simulate the information you had put in to work.

package cet3640.Fall13.Lab3;
/* 
 *Anton Scott 
 * 
 */
public class MobileDevice {

	private String deviceType;

	public MobileDevice()
	{

		deviceType = "Mobile Device";
	}

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

	public String getDeviceType() {
		return deviceType;
	}

}

package cet3640.Fall13.Lab3;

public class SmartPhone {

private String deviceType;

	public SmartPhone()
	{

		deviceType = "Smart Phone";
	}

public String getdeviceType()  {

	return String.format("Mobile Device" + " > " + deviceType);
	}

}

package cet3640.Fall13.Lab3;

public class IPhone extends SmartPhone {

		private String deviceType;

		public IPhone()
		{

			deviceType = "IPhone";
		}

	@Override	
		public String getdeviceType() {

			return String.format("Mobile Device" + " > " + "Smart Phone" + " >> " + deviceType);
		}
	}

package cet3640.Fall13.Lab3;

public class Android extends SmartPhone {

private String deviceType;

	public Android()
	{

		deviceType = "Android";
	}

@Override
	public String getdeviceType() {

		return String.format("Mobile Device" + " >> " + "Smart Phone" + " >>> " + deviceType);
	}

}

package cet3640.Fall13.Lab3;

public class windowsphone extends SmartPhone
{
	private String deviceType;

	public windowsphone()
	{

		deviceType = "Windows Phone";
	}

@Override
	public String getdeviceType() {
		return String.format("Mobile Device" + " >>> " + "Smart Phone" + " >>>> " + deviceType);
	}

}

package cet3640.Fall13.Lab3;

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());

	}

}
Lab 3 Part 1

Leave a Reply

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