Question

In: Computer Science

Create 3 Classes per the following instructions: 1) Create an abstract parent superclass called MobileDevices and...

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.

Solutions

Expert Solution

//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


Related Solutions

Java instructions: 1. Modify abstract superclass (Employee10A) so it comment out the abstract payPrint method and...
Java instructions: 1. Modify abstract superclass (Employee10A) so it comment out the abstract payPrint method and uses a toString method to print out it’s instance variables. Make sure toString method cannot be overridden.​​​​​​ Source code below: public abstract class Employee10A {    private String firstName, lastName; static int counter = 0;    public Employee10A(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; }    @Override public String toString() { return ("The employee's full name is " + firstName...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
Here I'm using "person" as an abstract superclass or parent class, and "Student" as a derived/child...
Here I'm using "person" as an abstract superclass or parent class, and "Student" as a derived/child class. // File name: Person.h // Person is the base, or parent for chapter11 #pragma once #include <iostream> #include <string> using namespace std; class Person { private:    string fName;    string lName;    int areaCode;    int phone; public:    Person();    Person(string, string);    void setFirst(string);    void setLast(string);    void setPhoneNumber(int, int);    string getFirstlast();    string getLastFirst();    string getPhoneNumber();...
This is in Java 1. Create an application called registrar that has the following classes: a....
This is in Java 1. Create an application called registrar that has the following classes: a. A student class that minimally stores the following data fields for a student:  Name  Student id number  Number of credits  Total grade points earned             And this class should also be provides the following methods:  A constructor that initializes the name and id fields  A method that returns the student name field  A method that returns the student...
CS Using the following UML outline, create the following abstract parent class along with the 4...
CS Using the following UML outline, create the following abstract parent class along with the 4 subclasses and Driver class. Implement the Classes, listed attributes and methods along with any additional things that you may need. Add a driver class that utilizes the methods/attributes in the classes to output the following based on the vehicle type (therefore, you must create an instance for all 4 subclasses in your driver): 1. Vehicle Type (i.e., Car, Airplane, etc.) 2. Transportation method (wheels,...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String variables called name1, name2, name3 3. Create 9 double variables called test1_1, test1_2, test1_3, test2_1, test2_2, test2_3, test3_1, test3_2, test3_3 4. Create 3 double variables called average1, average2, average3 To calculate the average score = (test1 + test2 + test3) / 3.0 5. Run the program with the following data using cin name1 = “Tom”, name2 = “Mary”, name3 = “Ali” test1_1 = 81.4,...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problems [30 marks] Problem 1: The Account class...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problem : The Fraction class (Filename: TestFraction.java) Design...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the...
Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the...
Exercise #1: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the user to choose game tester type...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT