Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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,

image text in transcribed
(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 methods for those variables. Finally add a method toString) to return the hard disk in formation 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 O 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 elass as the answers to this part. (d) Write a method showHardDisk0 of ComputerShop which loops through the keys of HardDi skMap using the enhanced for-loop and directly prints each hard disk object stored using System.out.printin.(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 mode1NumberSet 0 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.printin.Copy the content of the method, line(s) added and new execution output as the answers to this part [12) () Write a method sizeList 0 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 System.out.printin. Copy the content of the method, line(s) added and new execution out as the answers to this part display the list using

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

Use service tiering to manage the customer base and build loyalty.

Answered: 1 week ago