LAB DESCRIPTION:
Instructions:
1- Create a class called MobileDevice with a private field deviceType that will be initialized to the string “Mobile Device” in the constructor. Include the corresponding setter and getter methods.
2- Create another class SmartPhone that will inherit MobileDevice, with a private field deviceType initialized to the string “Smart Phone” in the constructor, and override the getter method by returning the string:
“Mobile Device -> Smart Phone”. (Hint: To obtain this result make a call to the super class getter method).
3- Create three more classes: Android, iPhone, and WindowsPhone that will inherit SmartPhone, have a private field deviceType initialized to the string “Android”, “iPhone”, or “Windows Phones” correspondingly in the constructor, and override the getter method returning the corresponding string
“Mobile Device -> Smart Phone -> iPhone” for iPhone,
“Mobile Device -> Smart Phone -> Android” for Android”, or
“Mobile Device -> Smart Phone -> Windows Phone” for Windows Phone.
CODE:
public class MobileDevice { private String deviceType; public MobileDevice(){ deviceType = "Mobile Device"; } public void setDeviceType(){ } public String getDeviceType(){ return deviceType; } /** * @param args */ } ___________________________________________________________________________________ public class SmartPhone extends MobileDevice { private String deviceType; public SmartPhone() { deviceType = "SmartPhone"; } public String getDeviceType() { deviceType = "Mobile Device -> Smart Phone"; return deviceType; } } ___________________________________________________________________________________ public class Android extends SmartPhone { private String DeviceType; public Android(){ DeviceType = "Android"; } public String getDeviceType(){ DeviceType = "Mobile Device -> Smart Phone -> Android -> NEXUS 4 "; return DeviceType; } } _________________________________________________________________________________________________________ public class iphone extends SmartPhone { private String DeviceType; public iphone(){ DeviceType = "iphone"; } public String getDeviceType(){ DeviceType = "Mobile Device -> Smart Phone -> iphone -> iphone 5S"; return DeviceType; } } ___________________________________________________________________________________ public class WindowsPhone extends SmartPhone { private String DeviceType; public WindowsPhone(){ DeviceType = "WindowsPhone"; } public String getDeviceType() { DeviceType = "Mobile Device -> Smart Phone -> Windows Phone -> NOKIA LUMIA 920 "; return DeviceType; } ___________________________________________________________________________________ public class MobileDeviceClient { /** * @param args */ 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()); } }
SCREENSHOTS: