0
/ 50
For this question assume the following implementations of Computer, Tablet, and Notebook
public class Computer { private String...
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 toString() {
return "My Computer is: \n Manufacturer: " + manufacturer
+ "\n CPU: " + processor + "\n RAM: " + ramSize
+ " gigabytes\n Disk: " + diskSize + " gigabytes\n Speed: "
+ processorSpeed + " gigahertz";
}
}
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);
}
}
Write a method that takes in a variable comp
of type Computer. If comp
is a Tablet, return the area. Otherwise, return the disk size of the computer.
Your feedback will appear here when you check your answer.