Question: Objective In this lab you will learn to implement class design; to design and implement a class. Exercise 1: Implement class design: Product You will

Objective In this lab you will learn to implement class design; to design and implement a class. Exercise 1: Implement class design: Product You will create the Product class and run with the test program. This class must implement the model in the following UML class diagram. 1. declare class fields to store the product name, price, product ID and total number of products; 2. implement a constructor that takes two parameters that populates the name and price fields; the variable total is incremented by one; the productID is populated by the current value of total; 3. implement a method getName that retrieves the product name; 4. implement a method getProductID that retrieves the product ID; 5. implement a method getPrice that retrieves the product price; 6. implement a method changePrice that changes the product price to the new price received as a parameter; 7. implement a method getTotal that retrieves the total number of products. Compile and run TestProduct program. You should have the following output: ***** You have 2 products now. You have Milk(ID=1). Its price is $2.50 You have Apple(ID=2). Its price is $6.00 ***** You have 3 products now. You have Milk(ID=1). Its price is $2.50 You have Apple(ID=2). Its price is $6.00 You have Bread(ID=3). Its price is $1.50 ***** You have 3 products now. You have Milk(ID=1). Its price is $2.50 You have Apple(ID=2). Its price is $5.99 You have Bread(ID=3). Its price is $1.50 Exercise 2: Design and implement a class: CashRegister Design and implement a CashRegister class that scans the product prices, counts the number of items and shows the total purchase. Hints: Scanning a product price is to take the price and add it to the total purchase; You do not need to consider rounding and formatting purchase values to dollars and cents in this exercise. First identify class fields (object state) that are required and methods (object behaviours) that are needed on the fields (accessor or mutator the state). Create a class diagram to describe your class design in the startup code CashRegister.java, using the following format. ============================== CashRegister ------------------------------ (fields here) ------------------------------ (methods here) ============================== Now, complete the main program, CheckOut.java, using your CashRegister class to scan products and display the number of items and total purchase as indicated in the program and follows. The CheckOut program will use your Product class created in Exercise 1. 1. Create a CashRegister object; 2. scan 3 products: Milk ($2.99), Apple ($5.49) and Bread ($1.75); 3. display the number of items purchased; 4. display the total purchase; 5. scan one more product: Apple; 6. display the number of items purchased; 7. display the total purchase; 8. create another CashRegister object; 9. scan 2 products: Milk and Bread; 10. display the number of items purchased; 11. display the total purchase. Compile and run CheckOut program. You should see the following output: ***** At Register 1 ***** You have purchased 3 items Total: $10.23 You have purchased 4 items Total: $15.72 ***** At Register 2 ***** You have purchased 2 items Total: $4.74

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!