Enter the name of the item you purchasing. bag Enter the quantity and price separated by a space. 3 1475.50 You are purchasing 3 bags (s) at 1475.5 each Amount due is 4426.50
Construct a simple purchasing program based on the UML class Diagram below.
Labexer2
-itemName:String
-itemPrice:double
-itemQuality:int
-amountDue:double
+setltemName:(String newItemName):void
+setTotalCost(int quantity,double price):void
+getltemName:():String
+getTotalCost():double
+readInput():void
+writeOutput():void
a. Writing import java.util. on the top of the code before the line for class name
b. Instantoating an object of the scanner class Scanner s = new Scanner (System.in)
c . Storing the input to the variable name based on data type
For String: s.nextLine()
For int: s.nextInt()
Foe double: s.nextDouble()
the write output() method will be used to display an output similar to the sample below
Sample output
Enter the name of the item you purchasing.
bag
Enter the quantity and price separated by a space.
3 1475.50
You are purchasing 3 bags (s) at 1475.5 each
Amount due is 4426.50
Step by step
Solved in 2 steps with 1 images