Lab Report 3

Lab Description:

We are given the client class, and we have to create the other classes to go with it. The other classes are suppose to be an experimental program for us to better understand the use of inheritance in java programming. We are to create one class, which is inherited by another class, which is inherited by 3 other classes.

Mobile Device

Smart Phone

Iphone  –  Windows Phone  –  Android

Code:

MobileDevice.java

package Lab3;

public class MobileDevice
{
    private String deviceType;

    public MobileDevice()
    {
        deviceType = "Mobile Device";
        setDeviceType();
    }

    public void setDeviceType()
    {
        deviceType = "Mobile Device";
    }

    public String getDeviceType()
    {
        return String.format("%s", deviceType);
    }
}

SmartPhone.java

package Lab3;

public class SmartPhone extends MobileDevice
{
    private String deviceType;

    public SmartPhone()
    {
        deviceType = "Smart Phone";
        setDeviceType();
    }

    public void setDeviceType()
    {
        deviceType = "Smart Phone";
    }

    @Override
    public String getDeviceType()
    {
        return String.format("%s >> %s", super.getDeviceType(), deviceType);
    }
}

Android.java

 package Lab3;

public class Android extends SmartPhone
{
    private String deviceType;

    public Android()
    {
        deviceType = "Android";
        setDeviceType();
    }

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

    @Override
    public String getDeviceType()
    {
        return String.format("%s >> %s", super.getDeviceType(), deviceType);
    }
}

iPhone.java

package Lab3;

public class iPhone extends SmartPhone
{
    private String deviceType;

    public iPhone()
    {
        deviceType = "iPhone";
        setDeviceType();
    }

    public void setDeviceType()
    {
        deviceType = "iPhone";
    }

    @Override
    public String getDeviceType()
    {
        return String.format("%s >> %s", super.getDeviceType(), deviceType);
    }
}

WindowsPhone.java

 package Lab3;

public class WindowsPhone extends SmartPhone
{
    private String deviceType;

    public WindowsPhone()
    {
        deviceType = "Windows Phone";
        setDeviceType();
    }

    public void setDeviceType()
    {
        deviceType = "Windows Phone";
    }

    @Override
    public String getDeviceType()
    {
        return String.format("%s >> %s", super.getDeviceType(), deviceType);
    }
}

 

Screenshots:

Lab 3

Leave a Reply

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