Description
For this lab we have to create an abstract class call MobileDevice with the private field of deviceType. Also we have to create three methods of setDeviceType to set the type of the device in the program that we used in the program. After we set all the function who where necessary to make the program work, we have to set all the array Devices that was need to be able to do this program working. The MobileDevices that we used were Iphone5, Android, SmartPhone and windowsPhone. For every single Devices that we used we had to create a bunch of of concrete class which will inherit from the superclass MobileDevice by using the keyboard extends. In the end we suppose to see after we run the program, the name of the Devices in order one after another.
Code
PART 1
package lab4;
public abstract class MobileDevice {
public String deviceType = “Device Type”;
public abstract void setDeviceType();
public String getDeviceType(){
return this.deviceType;
}
public String toString(){
return this.deviceType;
}
}
PART2
package lab4;
public class MobileDeviceApp {
public static void main(String[] args) {
MobileDevice[] mobileDevices = new MobileDevice[4];
mobileDevices[0] = new smartphone();
mobileDevices[1] = new Iphone5();
mobileDevices[2] = new androi();
mobileDevices[3] = new WindowsPhone();
for (MobileDevice m: mobileDevices){
System.out.println(“This device is: ” + m.toString());
}
}
}
PART 3
package lab4;
public class smartphone extends MobileDevice {
private String mySmartphone = “Smartphone”;
public void setDeviceType(){
this.mySmartphone = “Smartphone”;
}
public String getDeviceType(){
return this.mySmartphone;
}
public String toString(){
return this.mySmartphone;
}
}
PART 4
package lab4;
public class Iphone5 extends MobileDevice {
private String myPhone = “Iphone5”;
public void setDeviceType(){
this.myPhone = “Iphone5”;
}
public String getDeviceType(){
return this.myPhone;
}
public String toString(){
return this.myPhone;
}
}
PART 5
package lab4;
public class WindowsPhone extends MobileDevice {
private String mywindowsPhone = “windowsPhone”;
public void setDeviceType(){
this.mywindowsPhone = “windowsPhone”;
}
public String getDeviceType(){
return this.mywindowsPhone;
}
public String toString(){
return this.mywindowsPhone;
}
}
PART 6
package lab4;
public class androi extends MobileDevice {
private String myandroi = “androi”;
public void setDeviceType(){
this.myandroi = “androi”;
}
public String getDeviceType(){
return this.myandroi;
}
public String toString(){
return this.myandroi;
}
}
PrintScreen