Question: PLEASE USE VERY SIMPLE BEGINNER CODE LANGUAGE! Directions: Create a Bluej that implements the Phone class and the PhoneInventory class described below. Each class is
PLEASE USE VERY SIMPLE BEGINNER CODE LANGUAGE!
Directions: Create a Bluej that implements the Phone class and the PhoneInventory class described below. Each class is worth 50 points. When you are finished, zip the project folder and submit it.
- The Phone class represents a phone. It stores the phones manufacturer: manufacturer, name: name, quantity: quantity, number of times restocked: timesRestocked. Write the Phone class according to the following requirements.
- Add the four fields to the Phone class. Create a constructor that takes two parameters. The first parameter is a String named manufacturer that is used to initialize the phones manufacturer (i.e. Google, Samsung). The second and final parameter is a String named name that is used to initialize the phones name (i.e. Pixel 2XL, Galaxy S8+). The field timesRestocked should be initialized to zero (0). The field quantity should be initialized to a random number between 2 and 8 (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 phone. This is done by incrementing quantity by five (5) and incrementing timesRestocked by one (1).
- Write an accessor method to return the value of the field quantity.
- Write a method named phoneEquals 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 phoneToString that returns the details of this phone 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 PhoneInventory class represents a store phone inventory. It stores three Phone objects. You will write a constructor, a sellPhone method and a summary method for the class.
- Add the three object fields used by the PhoneInventory class. Create a constructor that initializes the three fields with the values: field one (Google, Pixel 2 XL), field two (Samsung, Galaxy S8+), and field three (Apple, iPhone X).
- Write a method named sellPhone. This method takes two parameters. The first parameter is a String named manufacturer that represents the manufacturer of the phone. The second parameter is a String named name that represents the name of the phone.
- If the manufacturer and name of the phone is in your inventory (hint - use the phoneEquals method of the phone in the if statement condition), use the purchase method of the phone to sell a phone. Use the accessor method of the phone to retrieve the quantity of the phone and store the value in a local variable called phoneQuantity.
- If the number of phones is less than or equal to two (2), print the following: You have phoneQuantity manufacuturer name phones left in stock. You are running low. Maybe it is time to restock? Then, use the restock method of the phone to restock the phone.
- Otherwise print the following message: You have sold a manufacturer name phone.
- If the phone is not in your inventory, the sellPhone method should print the following message: Sorry, we do not seem to have the manufacturer name phone in stock.
- If the manufacturer and name of the phone is in your inventory (hint - use the phoneEquals method of the phone in the if statement condition), use the purchase method of the phone to sell a phone. Use the accessor method of the phone to retrieve the quantity of the phone and store the value in a local variable called phoneQuantity.
- Write a method called summary that prints the current details of your phone inventory. This output should be formatted as shown in Example 2, below.
Example 1 (output showing the format for the phoneToString method of the Phone class):
Google Pixel 2 XL
-> You have 4 phones left.
-> This phone has been restocked 2 times.
Example 2 (output format for the summary method of the PhoneInventory class):
Phone Inventory Summary
-------------------------------------------------------------
Google Pixel 2 XL
-> You have 4 phones left.
-> This phone has been restocked 2 times.
-------------------------------------------------------------
Samsung Galaxy S8+
-> You have 7 phones left.
-> This phone has been restocked 0 times.
-------------------------------------------------------------
Apple iPhone X
-> You have 3 phones left.
-> This phone has been restocked 1 times.
-------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
