Description Modify your program from Assignment 3 that defined and tested a Comp
ID: 3750724 • Letter: D
Question
Description Modify your program from Assignment 3 that defined and tested a Computer class with a single hard drive to represent either a computer with a mechanical hard drive or computer with a solid-state drive. Pay careful attention to any changes within each individual class The Computer class represents a single Computer. Every Computer contains one of two HardDrives: a separately manufactured MechanicalHardDrive with a platter speed or a SolidStateDrive with a specified interface type The Computer class (provided) contains: A String data member named manufacturer that sets the manufacturer for the Computer .A String data member named model that sets the model for the Computer .A HardDrive data member named hardDrive that contains a HardDrive instance. A default no-arg constructor that creates a default Computer. Use appropriate mutator methods in your constructors. If this constructor is called, a new HardDrive instance should be created and set as the HardDrive for the Computer o Default values should be "OEM" for manufacturer, "Generic" for model A constructor that allows the client to set the HardDrive (by passing a HardDrive instance), Computer manufacturer, and Computer model. Use the appropriate mutator methods Accessor and mutator methods for all data members. These methods should be used throughout the class as needed. A method named toString() that returns a String indicating the manufacturer, model, hardDrive's capacity, and the textual description of the hardDrive from its toString() method (capacity and toString() data should be retrieved from the HardDrive instance). See expected output for the needed format. The HardDrive class should contain: . An int data member named capacity that indicates the storage capacity in GB A String data member named type that indicates the type of hard drive A default no-arg constructor that creates a default HardDrive. Use appropriate mutato methods in your constructors. Default values should be 256 for capacity and "Mechanical" for ty o pe.Explanation / Answer
Computer.java
public class Computer {
private String manufacturer;
private String model;
private HardDrive hd;
public Computer() {
hd = new HardDrive();
this.manufacturer = "OEM";
this.model = "Generic";
}
public Computer(HardDrive hd, String manufacturer, String model) {
setHd(hd);
setManufacturer(manufacturer);
setModel(model);
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public HardDrive getHd() {
return hd;
}
public void setHd(HardDrive hd) {
this.hd = hd;
}
@Override
public String toString() {
return manufacturer + " " + model + " " + hd;
}
}
_________________
HardDrive.java
public class HardDrive {
private int capacity;
private String type;
public HardDrive() {
this.capacity = 256;
this.type = "Mechanical";
}
public HardDrive(int capacity) {
this();
this.capacity = capacity;
}
public HardDrive(int capacity, String type) {
this();
this.capacity = capacity;
this.type = type;
}
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
if (capacity < 128)
this.capacity = 128;
else
this.capacity = capacity;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "Hard Drive Capacity :" + capacity + " GB Hard Drive Type:"
+ type;
}
}
______________________
MechanicalHardDrive.java
public class MechanicalHardDrive extends HardDrive {
private int platterSpeed;
public MechanicalHardDrive() {
setPlatterSpeed(5400);
}
public MechanicalHardDrive(int platterSpeed) {
this();
this.platterSpeed = platterSpeed;
}
public int getPlatterSpeed() {
return platterSpeed;
}
public void setPlatterSpeed(int platterSpeed) {
this.platterSpeed = platterSpeed;
}
@Override
public String toString() {
return super.toString() + " HardDrive Platter Speed :" + platterSpeed
+ " rpm";
}
}
___________________
SolidStateDrive.java
public class SolidStateDrive extends HardDrive {
private String interfaceType;
public SolidStateDrive() {
setInterfaceType("M.2");
}
public SolidStateDrive(String interfaceType) {
this();
setInterfaceType(interfaceType);
}
public String getInterfaceType() {
return interfaceType;
}
public void setInterfaceType(String interfaceType) {
this.interfaceType = interfaceType;
}
@Override
public String toString() {
return super.toString() + " Hard Drive Iinterface :" + interfaceType;
}
}
__________________
Main.java
public class Main {
public static void main(String[] args) {
SolidStateDrive ssd=new SolidStateDrive();
ssd.setCapacity(-250);
ssd.setType("Solid State");
MechanicalHardDrive mhd=new MechanicalHardDrive(7200);
mhd.setCapacity(256);
Computer c1=new Computer(ssd,"Lennovo","X1 Carbon");
Computer c2=new Computer(mhd,"Hp","Elite Desk");
System.out.println(c1);
System.out.println();
System.out.println(c2);
}
}
__________________
Output:
Lennovo X1 Carbon
Hard Drive Capacity :128 GB
Hard Drive Type:Solid State
Hard Drive Iinterface :M.2
Hp Elite Desk
Hard Drive Capacity :256 GB
Hard Drive Type:Mechanical
HardDrive Platter Speed :7200 rpm
_____Could you plz rate me well.Thank You