CET 3640 – Lab 4

Description:

In this laboratory, we created five different classes. The first being MobileDevice which is initialized to the private field “Mobile Device”. For this class we used the appropriate setter and getter methods. The rest of the classes include SmartPhone, Iphone, Android, WindowsPhone and MobileDeviceClient (Application). The application, MobileDeviceClient, then calls on the other classes and outputs the result.

 

Code:

public class MobileDevice {


private String devicetype = "Mobile Device";

public void setDeviceType () {

}

public String getDeviceType() {
return devicetype;
}

}

public class SmartPhone extends MobileDevice {

private String devicetype = "Mobile Device --> SmartPhone";

public void setDeviceType () {

}

public String getDeviceType () {

return devicetype;
}
}

public class Android extends SmartPhone{
private String devicetype;
public Android(){
devicetype = "Mobile Device --> Smart Phone--> Android";
}
@Override

public String getDeviceType()
{
return devicetype;
}
@Override

public void setDeviceType()
{
devicetype = "Android";
}
}

public class Iphone extends SmartPhone {

private String devicetype;
public Iphone(){
devicetype = "Mobile Device --> Smart Phone--> Iphone";
}
//@Override
public String getDeviceType()
{
return devicetype;
}
//@Override
public void setDeviceType()
{
devicetype = "Iphone";

}

}
public class WindowsPhone extends SmartPhone {
private String devicetype;
public WindowsPhone(){
devicetype = "Mobile Device --> Smart Phone--> WindowsPhone";
}
//@Override
public String getDeviceType()
{
return devicetype;
}
//@Override
public void setDeviceType()
{
devicetype = "WindowsPhone";

}
}
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(myAndroid.getDeviceType());
System.out.println(myIphone.getDeviceType());
System.out.println(myWindowsPhone.getDeviceType());

}
}

 Screenshot:

123

Leave a Reply

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