Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Directions: Create a Bluej project called Exam1 that implements the Headphone class and the HeadphoneInventory class described below. Each class is worth 50 points. When

Directions: Create a Bluej project called Exam1 that implements the Headphone class and the HeadphoneInventory class described below. Each class is worth 50 points. When you are finished, zip the project folder and submit it.

The Headphone class represents a headphone. It stores the headphones manufacturer: manufacturer, name: name, quantity: quantity, number of times restocked: timesRestocked. Write the Headphone class according to the following requirements.

Add the four fields to the Headphone class. Create a constructor that takes two parameters. The first parameter is a String named manufacturer that is used to initialize the headphones manufacturer (i.e. Bose, Sennheiser). The second and final parameter is a String named name that is used to initialize the headphones name (i.e. SoundLink, RS 195). The field timesRestocked should be initialized to zero (0). The field quantity should be initialized to a random number between 3 and 12 (inclusive). All fields must be declared private.

Write a method named purchase that is used to decrement the quantity by one (1).

Write a method named restock. This method is used to restock this particular headphone. This is done by incrementing quantity by three (3) and incrementing timesRestocked by one (1).

Write an accessor method to return the value of the field quantity.

Write a method named headphoneEquals that takes two (2) parameters and returns a boolean value. The first parameter is a String named manufacturer. The second parameter is a String named name. If the manufacturer and the name passed in to the method are the same as the manufacturer and name of this object, then return true. Otherwise they are not equal, so return false. Note: the case of the letters in the Strings should not make a difference.

Write a method named headphoneToString that returns the details of this headphone as a String. This String will include all four fields and needs to be formatted like Example 1 shown below. Hint: is the newline character.

The HeadphoneInventory class represents a store headphone inventory. It stores three Headphone objects. You will write a constructor, a sellHeadphone method and a summary method for the class.

Add the object three fields that are used by the HeadphoneInventory class. Create a constructor that initializes the three fields with the values: field one (Bose, SoundLink), field two (Sennheiser, RS 195), and field three (Koss, BT540i).

Write a method named sellHeadphone. This method takes two parameters. The first parameter is a String that represents the manufacturer of the headphone. The second parameter is a String that represents the name of the headphone.If the manufacturer and name of the headphone is in your inventory (hint - use the headphoneEquals method of the headphone in the if statement condition), use the purchase method of the headphone to sell a headphone. Use the accessor method of the headphone to retrieve the quantity of the headphone and store the value in a local variable called headphoneQuantity.

If the number of headphones is less than or equal to three (3), print the following: You have headphoneQuantity manufacuturer name headphones left in stock. You are running low. Maybe it is time to restock? Then, use the restock method of the headphone to restock the headphones.

Otherwise print the following message: You have sold a manufacturer name

If the headphone is not in your inventory, the sellHeadphone method should print the following message: Sorry, we do not seem to have the manufacturer name headphones in stock.

Write a method called summary that prints the current details of your headphone inventory. This output should be formatted as Example 2, below.

Example 1 (output format for the headphoneToString method of the Headphone class.)

Bose SoundLink

- You have 6 headphones left.

- This headphone has been restocked 2 times.

Example 2 (output format for the summary method of the HeadphoneInventory class.)

Headphone Summary

-------------------------------------------------------------

Bose SoundLink

- You have 6 headphones left.

- This headphone has been restocked 2 times.

======================================

Sennheiser RS 195

- You have 8 headphones left.

- This headphone has been restocked 0 times.

======================================

Koss BT540i

- You have 5 headphones left.

- This headphone has been restocked 1 times.

======================================

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

What is the purpose of an employee stock ownership plan (ESOP)?

Answered: 1 week ago