Objective:
The objective of this lab is to create an abstract class MobileDevice with a private field deviceType, and 3 methods: abstract setDeviceType(), concrete getDeviceType() and an overridden version of toString() that will display āMobile Deviceā. Then after creatingĀ the abstract classes, there willĀ be a set of concrete classes that will inherit MobileDevice .
This is an ilustration on how this lab should be implemented.
Source Codes:
Main Application:
public class MobileDevice1 { public static void main(String[] args ){ MobileDevice[] mobileDevices = new MobileDevice [6]; mobileDevices[0] = new Tablet(); mobileDevices[1] = new iPad3(); mobileDevices[2] = new KindleFireHD(); mobileDevices[3] = new SmartPhone(); mobileDevices[4] = new IPHONE5(); mobileDevices[5] = new SamnsungGalaxy3(); for (MobileDevice m: mobileDevices){ System.out.println("this device is: " + m.toString()); } } }
MobileDevice
public abstract class MobileDevice { private String deviceType = "Mobile Device"; public abstract void setDeviceType (); public String getDeviceType () { return this.deviceType; } public String toString () { return this.deviceType; } }
Tablet
public class Tablet extends MobileDevice { private String Tablet = "Tablet"; public void setDeviceType () { this.Tablet = "Tablet"; } public String getDeviceType (){ return this.Tablet; } public String toString (){ return this.Tablet; } }
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; } }
IPAD 3
public class iPad3 extends MobileDevice { private String iPad3 = "IPad3"; public void setDeviceType () { this.iPad3 = "iPad 3"; } public String getDeviceType () { return this.iPad3; } public String toString(){ return this.iPad3; } }
Samnsung Galaxy 3
public class SamnsungGalaxy3 extends MobileDevice { private String SamnsungGalaxy3 = "Samnsung Galaxy 3"; public void setDeviceType(){ this.SamnsungGalaxy3 = "Samnsung Galaxy 3"; } public String getDeviceType(){ return this.SamnsungGalaxy3; } public String toString (){ return this.SamnsungGalaxy3; } }
IPHONE 5
public class IPHONE5 extends MobileDevice { private String IPHONE5 = "IPHONE5"; public void setDeviceType () { this.IPHONE5 = "IPHONE 5"; } public String getDeviceType () { return this.IPHONE5; } public String toString(){ return this.IPHONE5; } }
Kindle Fire HD
public class KindleFireHD extends MobileDevice { private String KindleFireHd = "Kindle Fire Hd"; public void setDeviceType () { this.KindleFireHd = "Kindle Fire Hd"; } public String getDeviceType () { return this.KindleFireHd; } public String toString(){ return this.KindleFireHd; } }
Output: