Design a class named Item by compiling a UML diagram for the class.
Item
-name: String
-numInStock: int
-costPrice: double
-sellingPrice: double
+Item()
+Item(name: String, costPrice:double)
+getName(): String
+getNumInStock(): int
+getCostPrice(): double
+setNumInStock(numStock: int): void
+setSellingPrice(percProfit: double): void
+calcStockValue(): double
+sellItems(numToSell:int)
The class should contain:
A string data field named name for the items name.
An int data field named numInStock that stores the number of the item in stock.
A double data field named costPrice that stores the price that the item was purchased for.
A double data field named sellingPrice that stores the price that the item must be sold for.
Two overloaded constructors:
A default (no-argument) constructor that creates a default account (receives no values)
A constructor with two parameters that receives the name and cost price of the item. Assign the
parameter values to the relevant instance fields. Assign the value of 0 to the numInStock instance
field and the value of the costPrice to the sellingPrice instance field.
Accessor methods for all the instance fields.
Two mutator methods:
setNumInStock() that receives a value as the number of stock. Assign the value to the relevant
instance field.
setSellingPrice(percProfit:double) that receives the percentage profit that should be made on
the cost price of the item. Calculate and assign the selling price to the sellingPrice instance field.
Use the following information to do the calculation:
sellingPrice = costPrice + (costPrice * percProfit/100)
A method named sellItems() that receives the number of items to be sold. If the number received
is greater than the number of items in stock, return the value -1 which indicates that no items were
sold. If there is enough stock, subtract the number received from the number in stock and return
the value of 0.
A method named calcStockValue() that calculates and returns the stock value of items using the
costPrice multiplied by the and the number of items in stock.
toString() method to compiled and return an output string in the following format:
Name of item: xxxxxx
Cost price: R xxxxx.xx
Number in stock: xx
Selling price: R xxxxx.xx
Do the following:
Write code for the Item class as described in the section above.
Write a test program named testItem that allows the user to enter the name of an item and the
cost price of the item.
Instantiates (creates) an Item object calling the parameterised constructor with the name and cost
price of the item as arguments.
Call the setNumInStock() method to set the number of items in stock to the value 10
Call the setSellingPrice() method using the value of 50 as the % profit to be made on the cost
price of the item.
Use the toString() method to display the information of the Item object.
Call the calcStockValue() and display the value as follows:
Value of items in stock: R xxxxxx.xx
Selling items:
Display the heading Selling items
Use while .
Blooming Together_ Growing a Community Garden Worksheet.docx
Design a class named Item by compiling a UML diagram for the.pdf
1. Design a class named Item by compiling a UML diagram for the class.
Item
-name: String
-numInStock: int
-costPrice: double
-sellingPrice: double
+Item()
+Item(name: String, costPrice:double)
+getName(): String
+getNumInStock(): int
+getCostPrice(): double
+setNumInStock(numStock: int): void
+setSellingPrice(percProfit: double): void
+calcStockValue(): double
+sellItems(numToSell:int)
The class should contain:
A string data field named name for the items name.
An int data field named numInStock that stores the number of the item in stock.
A double data field named costPrice that stores the price that the item was purchased for.
A double data field named sellingPrice that stores the price that the item must be sold for.
Two overloaded constructors:
A default (no-argument) constructor that creates a default account (receives no values)
A constructor with two parameters that receives the name and cost price of the item. Assign the
parameter values to the relevant instance fields. Assign the value of 0 to the numInStock instance
field and the value of the costPrice to the sellingPrice instance field.
Accessor methods for all the instance fields.
Two mutator methods:
setNumInStock() that receives a value as the number of stock. Assign the value to the relevant
instance field.
setSellingPrice(percProfit:double) that receives the percentage profit that should be made on
the cost price of the item. Calculate and assign the selling price to the sellingPrice instance field.
Use the following information to do the calculation:
sellingPrice = costPrice + (costPrice * percProfit/100)
A method named sellItems() that receives the number of items to be sold. If the number received
is greater than the number of items in stock, return the value -1 which indicates that no items were
sold. If there is enough stock, subtract the number received from the number in stock and return
the value of 0.
A method named calcStockValue() that calculates and returns the stock value of items using the
costPrice multiplied by the and the number of items in stock.
toString() method to compiled and return an output string in the following format:
Name of item: xxxxxx
Cost price: R xxxxx.xx
2. Number in stock: xx
Selling price: R xxxxx.xx
Do the following:
Write code for the Item class as described in the section above.
Write a test program named testItem that allows the user to enter the name of an item and the
cost price of the item.
Instantiates (creates) an Item object calling the parameterised constructor with the name and cost
price of the item as arguments.
Call the setNumInStock() method to set the number of items in stock to the value 10
Call the setSellingPrice() method using the value of 50 as the % profit to be made on the cost
price of the item.
Use the toString() method to display the information of the Item object.
Call the calcStockValue() and display the value as follows:
Value of items in stock: R xxxxxx.xx
Selling items:
Display the heading Selling items
Use while loop to allow the user to how many items must be sold. While there are items in stock
and the input of the user is more than 0 do the following:
Call the sellItems() method to sell the items. If the method returns the value of -1, display a
message indicating that there is not enough stock. Also display the number of items in stock by
calling the getNumInStock() method.
If there is enough stock, display a message indicating that the items were sold.
Also display the number of items in stock (after the sale) by calling the getNumInStock() method.
Example of output if the input is Bag as the name of the item and R150.00 as the cost price:
Name of item: Bag
Cost price: R 150.00
Number in stock: 10
Selling price: R 225.00
Value of items in stock: R 1500.00
Selling items:
Enter the number of items to sell (0 to quit):
4
Number of items sold: 4
Number of items in stock: 6
Enter the number of items to sell (0 to quit):
8
Not enough stock
Number of items in stock: 6
Enter the number of items to sell (0 to quit):
6
Number of items sold: 6
Number of items in stock: 0