Question
Implement the class Device. In this question, you are required to declare all the attributes and methods (the constructor, the getters/setter methods...) as presented in
Implement the class Device. In this question, you are required to declare all the attributes and methods (the constructor, the getters/setter methods...) as presented in the UML diagram.
- The class is abstract and contains an abstract method named isAlternative.
- The method toString method returns a String of the form Brand: . Price: . dollars.
Implement the class Laptop. It has two private attributes. The cpu (corei5, corei7) and the type that indicates whether the Laptop is ultrabook, notebook, etc.
- Implement the constructor and the getter/setter methods
- b.The toString method returns a String of the form:
Laptop Brand: . Price . dollars.
Cpu: And Type:
the USB code:
public class Usb extends Device {
private int storage;
public Usb(String brand, double price, int s) {
super(brand, price);
this.storage = s;
}
@Override
public String toString() {
return "Usb " + super.toString() + " Storage is" + storage + " GB " ;
}
@Override
public boolean isAlternative(Object o) {
return true;
}}
Continue the implementation of the class Laptop
- Implement the isAlternative method of signature public boolean isAlternative (Object o). Two Laptops are alternatives if they have the same type and the same cpu.
Implement the class TechShop.
- Constructor: set the name of the TechShop, and initializes the ArrayList for devices.
- addDevice (device: Device) : This method adds a Device to devices ArrayList.
- getDevices() : This method returns the list of devices.
Continue the implementation of the class TechShop. Implement the toString method. It returns information about all the devices in the ArrayList devices.
TechShop Name: Modern Technology
Devices: Laptop Brand: HP Price: 500 dollars.
Cpu: corei7 And Type:Ultrabook
Laptop Brand: Lenovo Price 600 dollars.
Cpu: corei5 And Type:Notebook
Usb Brand: SanDisk Price: 30 dollars.
Storage is 32 GB
main:
- Creates a TechShop called Modern Technology.
- Add three objects to the TechShop, two Laptops (Laptop1 and Laptop2) and a USB from values set by the programmer.
- Display information about all the Laptops in the TechShop that could be alternative to Laptopl.
- Display all information about laptops in the TechShop whose type is Ultrabook and cpu is corei7.
java.util.ArrayList
+ArrayList()
+add(o: E): void
+add(index: int, o: E): void
+clear(): void
+contains(o: Object): boolean
+get(index: int): E
+indexOf(o: Object): int
+isEmpty(): boolean
+lastIndexOf(o: Object): int
+remove(o: Object): boolean
+size(): int
+remove(index: int): boolean
+set(index: int, o: E): E
TechShop -name: String - devices: ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started