In: Computer Science
Create 3 Classes per the following instructions:
1) Create an abstract parent superclass called MobileDevices and include only the attributes that are common to both cellphones and tablets like iPads. Also create at least one abstract method.
2) Create a child class that extends the MobileDevices class called DeviceType that has attributes and methods regarding the type of device.
3) Create a third class that extends the DeviceType class called DeviceBrand that has attributes and methods for both Apple and Android devices. Make sure to create methods that override any methods in the superclass and possibly any parent class.
4) Create a driver class that initializes the classes and prints out values. Submit you .java files with your name appended to the file names and screenshots of your output.
//Java code
public abstract class MobileDevices { protected String deviceName; //constructor public MobileDevices(String deviceName) { this.deviceName = deviceName; } public abstract void setDeviceName(String name); public String getDeviceName() { return deviceName; } @Override public String toString() { return deviceName; } }
//====================================
public class DeviceType extends MobileDevices{ private String type; //Constructor public DeviceType(String deviceName, String type) { super(deviceName); this.type = type; } //getters and setter public String getType() { return type; } public void setType(String type) { this.type = type; } @Override public void setDeviceName(String name) { deviceName = name; } @Override public String toString() { return super.toString()+" " +type; } }
//=======================================
public class DeviceBrand extends DeviceType{ private String brandName; //Constructor public DeviceBrand(String deviceName, String type, String brandName) { super(deviceName, type); this.brandName = brandName; } @Override public String toString() { return super.toString()+" "+brandName; } }
//============================================
public class Driver { public static void main(String[] args) { MobileDevices mobile1 = new DeviceBrand("iPad","Tablet","Apple"); MobileDevices mobile2 = new DeviceBrand("Android","SmartPhone","Google Pixel"); //Print info System.out.println(mobile1); System.out.println(mobile2); } }
//============output========================
//If you need any help regarding this solution .............please leave a comment ........ thanks