(40 Marks) Based on UML class diagram presented in Figure 1, you are require to complete the java program source code in
Posted: Tue Jul 12, 2022 8:20 am
WELCOME TO THE XYZ DRINK SELLING Drink available: Price: 150(cents) Price: 180(cents) 1 COKE 2 MILK 3 MILO 4 WATER 5 PEPSI - Price: 200(cents) - Price: 120(cents) - Price: 150(cents) Please select your drink: Please enter coins as follows: pum of 10 cents coins, num of 20 cents coins,num of 50 cents coins,num of 1 Ringgit (100 cents) coins Example: If you would like to enter 2 ten cents coins: 2,0,0,0 Plese enter coins: 2,2,2,3 Your change is :260cents splitted as follows: 1 Ringgit (100 cents) coins: 2 50 cents, coins: 1 20 cents coins: 10 cents coins: 1 Figure 2: Sample Output 1 WELCOME TO THE XYZ DRINK SELLING Drink available: Price: 150(cents) 1 COKE 2 MILK Price: 180(cents) 3 MILO Price: 200(cents) 4 WATER - Price: 120(cents) S PEPSI Price: 150(cents) Please select your drink:- Please enter coins as follows: num of 10 cents coins, num of 20 cents coins, num of 50 cents coins,num of 1 Ringgit (100 cents) coins Example: If you would like to enter 2 ten cents coins: 2,0,0,0 Plese enter coins: 1,2,1,2 Your change is :180cents splitted as follows: 1 Ringgit (100 cents) coins: 1 50 cents coins: 1 20 cents coins: 1 10 cents coins: 1 Figure 3: Sample Output 2 Complete the program based on the following tasks. Note that, the tasks are also stated in the program source code in the given templates. The tasks are labeled as Task I to Task 4. IMPORTANT NOTE: Do not modify existing code in the given templates. Only modify the codes based on the comments/instructions stated in Task I to Task 4.
Task 1: In DrinkList.java; This file contains an enumerated type declaration of DrinkList with a list of coin types and prices. Do the following task, i) Complete the enum declaration using the data stated in Table 1. Drink Type COKE MILK MILO WATER PEPSI EMPTY Table 1: Data to be used in DrinkList enum Selection number 1 2 3 4 5 0 (6 Marks) Price in cents 150 180 200 120 150 0 Note: Constant values of the DrinkList enum is the type of drinks, while the selection. number and price are the fields of each constant value. (12 Marks) Task 2: In CoinType.java, Calculator.java and Coin.java: There is an association relationships among Coin, which is a type of class with CoinType and Calculator classes. Do the following tasks; i) There are errors found in the following statements in Calculator.java. Correct the errors. The method getValue () must be able to functions correctly, to show the association relationship between CoinType and enum Coin //red highlighted texts need modification change.num1Ringgit - remaining Amount / getValue(); remainingAmount remainingAmount & getValue (); change.num50cents Coins remainingAmount / getValue();
remainingAmount = remainingAmount 8 getValue (); change.num20 CentsCoins = remaining Amount / getValue (); remainingAmount = remainingAmount getValue (); change.num10 Cents Coins = remaining Amount / getValue (); remainingAmount = remainingAmount getValue (); ii) There are errors found in the following statements in CoinType.java. Correct the errors. The method getValue () must be able to function correctly, to show the association relationship between CoinType and enum Coin //red highlighted texts need modification total total+this.num10 Cents Coins* getValue (); total = total+this.num20 Cents Coins* getValue (); total total+this.num50 Cents Coins* getValue (); total = total+this.numlRinggit getValue ();
Task 3: (6 Marks) In CointType.java; In this class, 4 integer variables are used to store the numbers of coins entered by the user. The variables as follows; num10Cents Coins, num20CentsCoins, num50 CentsCoins and num1Ringgit to calculate the total value of the money. Do the following task; i) Modify the codes, no integer variables are used to store the numbers of coins. Use a single ArrayList object to calculate the total value of the money. ii) Modify the statements in CoinType () constructor. Add elements in coinsDropp [] using proper ArrayList method.
Task 4: In CoinType.java, Calculator.java and DrinkSellingSystem.java; Modification of the CoinType.java will affect the other classes since there has an aggregation relationship between ✓ CoinType.java and DrinkSelling System.java ✔✓ CoinType.java and Calculator.java. Do the following tasks, i) ii) iii) (16 Marks) CoinType.java In getTotal (): modify the following statements by using proper ArrayList method. //red highlighted texts need modification total total+ this.num10Cents Coins total total+this.num20cents Coins total total+this.num50cents Coins total total+this.numlRinggit* getValue(); getValue (); getValue (); getValue (); Calculator.java In calculateChange (): modify the following statements by using proper ArrayList method //the following statements need modification change.numlRinggit = remainingAmount/getValue(); change.num50cents Coins remainingAmount/ getValue (); change.num20cents Coins remainingAmount/ getValue (); change.num10Cents Coins remainingAmount/ getValue (); DrinkSellingSystem.java In displayChangeMessage (), modify the following statements by using proper ArrayList method // red highlighted texts need modification System.out.println(" 1 Ringgit (100 cents) coins: " change.numiRinggit); System.out.println(" 50 cents coins: " change.num50CentsCoins); System.out.println(" 20 cents coins: "+change.num20CentaCoins); System.out.println(" 10 cents coins: " change.num10CentsCoins);