Create an Account

Already have account?

Forgot Your Password ?

Home / Questions / Write a class named RetailItem that holds data about an item in a retail store...

Write a class named RetailItem that holds data about an item in a retail store...

Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the
following fields:
• description. The description field references a String object that holds a brief description of the item.
• unitsOnHand. The unitsOnHand field is an int variable that holds the numbers of units currently in inventory.
• price. The price filed is a double that holds the item's retail price.
Write a constructor that accepts arguments for each field, appropriate mutator methods that store values in these
fields, and accessor methods that returns the values in these fields.
After this, write a method in the RetailItem class called purchaseItem. This method will be used to simulate an item(s)
purchase. It will accept as a parameter the variable totalItemsToPurchase representing a number of units to buy (e.g.
10). The method should check if its unitsOnHand is enough to satisfy the purchase. If it is not, notify the user. If it is
enough, update unitsOnHand with the new value (unitsOnHand – totalItemsToPurchase) and return to the user the total
cost of the purchase (itemsToPurchase * price).

Attachments:

Apr 02 2020 View more View Less

Answer (Solved)

question Subscribe To Get Solution

Related Questions