X780: Get Model

For this question assume the following implementations of Computer, Tablet, and Notebook

public class Computer {
    private String manufacturer;
    private String processor;
    private int ramSize;
    private int diskSize;
    private double processorSpeed;

    public Computer(String man, String pro, int raSize, int diSize, double proSpeed) {
        manufacturer = man;
        processor = pro;
        ramSize = raSize;
        diskSize = diSize;
        processorSpeed = proSpeed;
    }


    public String getManufacturer() {
        return manufacturer;
    }


    public int getRamSize() {
        return ramSize;
    }


    public int getDiskSize() {
        return diskSize;
    }


    public double getProcessorSpeed() {
        return processorSpeed;
    }


    public String getModel() {
            return this.getManufacturer() + "_" + this.getProcessorSpeed();
        }

}

public class Tablet extends Computer{
    private int length;
    private int width;
    private String operatingSystem;

    public Tablet(String man, String pro, int raSize, int diSize, double proSpeed, int len, int wid, String os) {
        super(man, pro, raSize, diSize, proSpeed);
        length = len;
        width = wid;
        operatingSystem = os;
    }

    public int getArea() {
        return length * width;
    }

    @Override
    public String toString() {
        return "My Tablet was made by: " + getManufacturer()
            + ", and has a screen area of: " + getArea();
    }

}

public class Notebook extends Computer{
    public Notebook(String man, String pro, int raSize, int diSize, double proSpeed) {
        super(man, pro, raSize, diSize, proSpeed);
    }
}

For this exercise, you will be writing a new method for the Tablet class. Write a method that overrides Computer getModel, that adds the width and length to the string returned. Since the method is within the Tablet class you can access the fields of the Tablet class directly.

For example:

  • If I had a Computer object where manufacturer = "MAN" and processorSpeed = 5.5, then running getModel would return the string "MAN_5.5"
  • If I had a Tablet where Manufacturer was MAN, processorSpeed was 5.5, width was 8.5, and length was 11, then running getModel would return "MAN_5.5_8.5_11"

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.