Project4 CECS277 

$30.00 $15.00

Download Details:

  • Name: Project4-xjh28o.zip
  • Type: zip
  • Size: 178.86 KB

Category:

Description

Rate this product

Inventory Class

Design an Inventory class that can hold information for an item in a retail store’s inventory.
The class should have the following private member variables.
Variable Name Description
itemNumber An int that holds the item’s number.
quantity An int that holds the quantity of the item on hand.
cost A double that holds the wholesale per-unit cost of the item
Member Methods Description
default constructor Sets all the member variables to 0.
constructor #2 Accepts an item’s number, quantity, and cost as arguments.
Calls other class methods to copy these values into the appropriate member
variables.
setItemNumber Accepts an int argument and copies it into the itemNumber member variable.
setQuantity Accepts an int argument and copies it into the quantity member variable.
setCost Accepts a double argument and copies it into the cost member variable.
getItemNumber Returns the value in itemNumber.
getQuantity Returns the value in quantity.
getCost Returns the value in cost.
getTotalCost Computes and returns the totalCost.
Boolean ValidInt(int) validates for integer values entered by the user not to be negative. Call this
method from setItemNumber, and setQuantity. Program should loop if negative values entered.
Boolean ValidFloat(double) validates for cost entered by the user not to be negative. Call this
method from setCost. Program should loop if negative values entered.
Demonstrate the class by writing a simple client program that uses it. This program should user
inputs and validate the user inputs to ensure that negative values are not accepted for item
number, quantity, or cost.
I executed the jar file generated on the command line the way it was
described during lecture.
java -jar project4.jar
Please see the sample output.
Enter the Item number: -11
Item Number must be 0 or greater. Please re-enter:
1234
Enter the quantity: -12
Quantity must be 0 or greater. Please re-enter:
10
Enter the cost for each item: $-102
Cost must be 0 or greater. Please re-enter
124
Item number: 1234
Quantity : 10
Cost $124.00
Total Cost : $1240.00
Demonstrating the default constructor…
Item number: 0
Quantity : 0
Cost 0.0
Total Cost : 0.0
Demonstrating the overloaded constructor…
Item number: 124
Quantity : 12
Cost : $84.95
Total Cost : $1019.40
Demonstrating the “set” functions…
Item number: 243
Quantity : 50
Cost : $9.50
Total Cost : $475.00
Demonstrating the input validation functions…