CET 3640 LAB 3

Lab Description

We are creating a class called MobileDevice with a private field deviceType that will be initialized to the string “Mobile Device” in the constructor. Then create a SmartPhone class that will inherit MobileDevice. Then Android, iphone, and WindowsPhone to inherit SmartPhone class. The output will be

Mobile Device

Mobile Device -> SmartPhone

Mobile Device -> SmartPhone -> iPhone

Mobile Device -> SmartPhone -> Android

Mobile Device -> SmartPhone -> WindowsPhone

Code

 

public class MobileDevice {
    private String deviceType = "Mobile Device";
    public void deviceType() {
        deviceType = "Mobile Device";
    }
    public String getDeviceType(){
        return this.deviceType;
    }
}

public class SmartPhone extends MobileDevice {
    private String mySmartPhone = "SmartPhone";  
    public SmartPhone(){
        mySmartPhone = "SmartPhone";
    }
    public void setDeviceType(){
        this.mySmartPhone = "SmartPhone";
    }

    public String getDeviceType(){
        return super.getDeviceType() + " -> " + mySmartPhone;    
    }
}

public class iPhone extends SmartPhone  {
    private String myiPhone = "iPhone";

    public iPhone(){
        myiPhone = "iPhone";
    }   
    public void setDeviceType(){
        this.myiPhone = "iPhone";
    }
    public String getDeviceType(){
        return super.getDeviceType()+ " -> " + myiPhone;
    }
}

public class Android extends SmartPhone{
        private String myAndroid = "Android"; 
        public Android(){
            myAndroid = "Android";
        }        
        public void setDeviceType(){
            this.myAndroid = "Android";
        }
        public String getDeviceType(){ 
            return super.getDeviceType()+ " -> " + myAndroid;
        }
 }

public class WindowsPhone extends SmartPhone {
        private String myWindowsPhone = "WindowsPhone"; 
        public WindowsPhone(){
            myWindowsPhone = "WindowsPhone";
        }
        public void setDeviceType(){
            this.myWindowsPhone = "WindowsPhone";
        }
        public String getDeviceType(){
            return super.getDeviceType()+ " -> " + myWindowsPhone;  
        }
    }

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

Screenshot from 2013-10-21 00:49:13

 

 

 

Leave a Reply

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