Question: Java Question Display following output: brand: Seagate, model number : STDR2000306, size : 2.0 brand: Western Digital, model number : WD4002VYYZ, size : 4.0 [STDR2000306,
Java Question

Display following output:
brand: Seagate, model number : STDR2000306, size : 2.0
brand: Western Digital, model number : WD4002VYYZ, size : 4.0
[STDR2000306, WD4002VYYZ]
[2.0, 4.0]
(a) Create a class HardDisk which stores the information of a hard disk. It includes the brand, the model number (String) and the size (double, in TB). Write a constructor of the class to so that the information mentioned is initialized when a HardDisk object is created. Also write the getter method:s for those variables. Finally add a method toString () to return the hard disk information in the following string form "brand: Western Digital, model number: WD4002VYYZ, size: 4" Copy the content of the class as the answers to this part. [12] (b) Create a class ComputerShop which stores the hard disk information in a map HardDiskMap, whose key is the concatenation of the brand and model number, separated by ": " (a colon and a space) Write a method addHardDisk (HardDisk oneHardDisk) which adds oneHardDisk to HardDiskMap. Copy the content of the class, which any include import statement(s) required, as the answers to this part (c) Create a class TestComputerShop with a main() method which creates a ComputerShop object aShop and add the first hard disk with brand "Western Digital", model number "WD4002VYYZ" and size 4. Add the second hard disk with brand "Seagate", model number "sTDR2000306" and size 2. Copy the content of the class as the answers to this part (d) Write a method showHardDisk() of computerShop which loops through the keys of HardDiskMap using the enhanced for-loop and directly prints each hard disk object stored using System.out.println (). (Loop through the values is simpler but using the keys is required in this part.) This should show suitable information since the method toString () has been written in (a) Add a statement in TestComputershop to display all the hard disk information of aShop. Copy the content of the method, line(s) added and execution output as the answers to this part (e) Write a method modelNumberSet () of computerShop which returns model numbers of the hard disks in a set. You should loop through the values of HardDiskMap using the enhanced for-loop and collect the model numbers. Add a statement in TestComputershop to display the set using System.out.println (). Copy the content of the method, line(s) added and new execution output as the answers to this part [12] (f) Write a method sizeList ) of computerShop which returns the sizes of the hard disks in a list. You should loop through the values of HardDiskMap using the enhanced for-loop and collect the sizes of the hard disks. Add a statement in TestComputerShop to display the list using System.out.println (). Copy the content of the method, line(s) added and new execution output as the answers to this part
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
