Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help and show detailed Java code, thanks (a) Create a class HardDisk which stores the information of a hard disk. It includes the brand,

Please help and show detailed Java code, thanks

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 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 Computer Shop 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 Tes tComputerShop with a main method which creates a ComputerShop object a Shop 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 Computer Shop which loops through the keys of HardDis kMap using the enhanced for-loop and directly prints each hard disk object stored using System.out.print1n (). (Loop through the values is simpler but using the keys is required in this part.) This should show suitable information since the method tostringhas been written in (a) Add a statement in TestComputer Shop 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 modelNumber Set ofComputerShop which retums 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.print ln. Copy the content of the method, line(s) added and new exccution output as the answers to this part. [12] ( Write a method sizeListO of ComputerShop which retums the sizes of the hard disks in a list. You should loop through the values of HardDi skMap 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.print ln. Copy the content of the method, line(s) added and new exccution output as the answers to this part

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 Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions