MIS 132 Object Orientd Programming 2022\2023 Spring Homework #2 Develop the menu driven java program with exception handling for transactions of a retail company. A retail company sells different products such as food, electronic equipments, and beverages. These products are sold to different types of customers of the company with different promotions. There are product specific promotions or transaction specific ones. Transaction promotions depend on customer type. Custmers gain points depending on the total value of transction after all discounts are deduced. How to accumulate points also depend on customer type. Registered customers can use some of their points for payment or added to total points of the customer For some transactions there may not be a registered customer at all in that case only product promotions are applied which are independent of customer type or even when there is no registered customer associated with the transaction. Develop a menu driven Java program to calculate total payment of a customer,,when a transaction is completed. Managers also use this program to monitor total revenue and discounts from different promotion or customer types. In case of wrong entry the program use exception handling and does not crash. Use polymorphism and software reusability as much as possible Here are the class descriptions. Add any other relevant variable or method as required. Write constructors, get, set, display and any other methods as needed. Create the Product class holding name, price and type of the product. All products have value added tax rate. Some products are luxury in that they are subject to a higher value added tax than ordinary products. Do not develop different product classes for normal or luxury products but indicate by a boolean variable in the product class whether the product type is luxury or normal. Value added tax rates for normal and luxury products are not product specific. There is only one value added tax rate applied to normal products and another one for luxury products. Define these rates properly in the Product class. Create the abstract Customer class holding name and ID of the customer. Customer ID is an integer, used to find the customer in the customer Arraylist. Create two concrete customer classes as Regular and Gold Both types of customers benefit from product specific promotions via the same procedure but transaction promotions depends on customer type. Golds benefit from transaction specific promotions with higher promotion rates than regulars. These promotion rates are not customer specific and defined in the appropriate customer classes in a proper way as will be explained later. Each type of customer gets points as they make purchases from the store. The point accumulation rates of these type of customers are different (depends on customer type only – class specific). Develop proper customer classes as the subclasses of the abstract Customer class. Promotions are calculated after value added tax is added to the products’ base price. promotions are calculated then deduced from payments. Points gained by customers are calculated based on net value of the transaction after deducing all discounts. Optionally registered customers can use some of their points in payment of the current transaction. There are two broad promotion types as mentioned above; product specific or transaction promotions. Product specific promotions are associated with Products. So Product class should have a productPromotion variable which is a percentage value set by a proper method if the products sold with a promotion. x% discount is applied on price plus VAT. For each product the %x value may be different even can be changed during the course of the program in the test class. Example: Suppose product apple (a normal product) is decided to be promoted, set the promotion variable to a percentage value, say 0.15, price of apple is 20, VAT for normal products: 10% a transaction contains 2 kg of aapple. Total amount = 2*(20+20*0.1)*(1-0.15) = 44 – 6.6 = 37.4 The transaction promotions are calculated after the product promotions are calculated and subtracted from the value of transactions. Example suppose in a transaction the customer adds 2 kg apples and 3 kg pairs to her basket. Apple price is 20, pair price is 30 suppose apple is normal and pair is luxury. Normal VAT is 0.1 luxury VAT is 0.2. Apples are sold with product promotion rate of 0.15, pairs are sold with promotion rate of 0.05. What is the amount of money the customer would pay for this transaction? (value of the transaction after product promotions are calculated and subtracted from the gross valued of transaction) value after product promotions = 2*((20*1.1.*(1-0.15) (for 2 kg of apples) +3*30*1.2*(1-0.05) (for 3 kg of pairs) = 44*0.85 + 108*0.95 Value of transaction = 44 – 6.6 + 108 – 5.4 = 140 Transaction promotions for gold customers:.z percent of the total value of the transaction based on original prices plus value added tax and subtracting product promotions. The same customer promotion rate z is applied for all gold customers. In the previous example if the customer is a gold one and z value is 0.02 value of transaction after product promotions is 140 TL and z% is 2 , the customer has a transaction promotion of 2.8 (140*0.02) and total value of the transaction is : 140-2.8 = 137.2 For regular customers: if the transaction value exceeds a limit value (which is applicable to all regular customers) for each TL exceeding this limit the discount is zR%. Ex: if limit is 40 and zR is 0.05 and value of the transaction (after product promotions) is 140, discount due to transaction promotion for a regular customer is (140-40)* 0.05 = 5 TL Note on implementations: declare a transactionPromotion method in the abstract Customer class. Implement in each subclass. This method takes the value of transaction after product promotions and return discout from transaction promotion. Define the limit parameters, zR and z paamters in relevant customer classes. Gaining points: For gold customer zP% of the net transaction value after subtracting transaction discounts is accumulated as points.. For regular customers if final value of transaction exceeds a PointLimit PLR, %zPR percent is accumulated as points. Example: for gold customers if zP value is 0.03 3% of the net value of a transaction is added to the points In previous example: net value was 137.2, so the gold customer gains new 1.375*3 points. If point limit is 100 and %2 PR = 0.02, the regular customer’s gains: (135 - 100)*0.02 = 2 points. Implementation: implement the gainPoint methods similar to transactionPromotion methods: define in each concrete customer class taking the net value of transaction after all promotions and calculating and adding total points of each customer. The Transaction class: Each transaction is associated optionally with a registered customer, some has no registered customers. Products purchased are hold in an ArrayList of Product amount pairs, a Product object is followed by an Integer or Double object representing number of amout of that product added to the basket. Write an addbasket method to add a product amount pair to the end of the ArrayList. There is no cancel method in this version. Once a product and amount pair is asked to customer and added to the basket, no way to cancel it for simplicity. The traction class has a customer variable in case the buyer is one of the registered types of customers (regular or gold otherwise remains as null). The Invoice method of the Transaction class calculates and returns the total payment of the tramsaction. (Including value added tax and all discounts) , discount made to this customer from this transaction (discounts from both product promotions and transaction promotions). Update the points of the customer a registerd customer is associated. Present all (net value of transaction and currently total accumulated points) to the screen and ask the customer how much of her accumulated points to use. Based on the input entered, calculate and present the total payment and updates the total points if customer if she uses some in the payment. This method throws some user defined exceptions as explained bellow as well. In the test class: Create 4 products (insert into an generic ArrayList of Product), 2 are normal and the other 2 are luxury porudcts. One of the normal products are sold with product promotion, and one of the luxary products is sold with porotion again. Define the promotion rates while creating the products. If no promotion is applied you can set the rates to zere. Create two regular and two gold customers. (store the customers of the company into another generic ArrayList of Customer as well). A new transaction is created as the customer enters to shop. Let the customer purchase some products, add the the basket. Associate some of these transactions with either type of customers even some transactions should have no customers at all.. After adding products to basket ends, calculate and print invoices of these transaction via the invoice method. Store each transaction into an ArrayList of Transactions as well. In the test class there should be three ArrayLists as: customers, products and transactions. Initially all customers and products are defined and inserterd into these ArrayLists. In the exectution of the program no new products and customers are created online. Initially transactionlist is empty, as new tranactions occur, added to the proper ArrayList online. Note that no object is crerated from the Test class. Traversing over these lists management of the store should learn total revenue, total discounts make in transactions including product and transaction promotions, Each customer can be quaried for her total points as well. When the program starts running a menu is seen 1: customer, 2 manager, all other integers entered exits from the program. Once understand the user is a customer or manager, call a proper method for customers and managers respectively to increase readability of the program; not to load the main method with so many line of code. For customers call the customerOpps and for managers call the managementOpps methods For customers: If the user enters 1 then asks customer ID. If this is a defined customer (gold or regulsr) she can be forum in the ArrayList of customers. If not a registered customer enter ID as 0, so that the program interpret her as a unregistered customer that cannot benefit from transaction promotions as explained above. A new transaction is created ask user to enter two number in a line product ID and how many are purchased. And the user proess ENTER Product ID 0 means the end of products Example: Enter product and amount pairs: 1 2 ENTER 2 3 ENTER 0 1 ENTER The user sees the message “Enter product and amount pairs:” the program expects the user to enter some information. In the first line the user enters 1 2 end press ENTER. That means buy 2 kgs of say apple with product ID 1. In th second line 2 3 ENTER is add basket 3 kgs of product pair with ID say 2. In the third line the product ID is 0 so this can be interpreted as there is no such product the is the end of transaction.(no more product quantity paris are added to the basket) They are added properly to the newly created transaction object. Assume ther is no delate option; customer cannot delete a product from the basket. Then the invoice method calculates the total value, total value added tax product and transaction promotions and presents to the screen as well as the accumulated points if this is a registered customer. Asks the customer how much points to use, get the information from the user and caluates the overall payment and the final value of the points of the customer and meke necessary updates. And exit from the program. Exception handling: If the customer ID entered is not found in the list of customers or it is not 0, the customerOpps mehod throws a user defined exception (an unchecked exception) re ask the proper ID until the user enters a proper one (a registered customer or 0). Handle the exception in the customerOpps method. While asking product quantity pairs, if the amount is less than 0, the addbasket method throws an user defiend exception, which is handled at the mehhod addbasket. If the ID ot the products is not a valid ID(no such product is found in the products ArrayList), another user defined exceptin is thrown by the addbasket method which is handled their. Example Enter product and amount pairs: 1 -5 ENTER Amount cannot be negative reenter the line (his is the exceptions message displayed to user) 1 2 ENTER (this is a proper line, the item 1 with 2kg is added to basket) 7 3 ENTER No item with this id reenter the line (this is the exception handling message, the user is asked to enter the line again expected to enter a proper product.) 7 3 ENTER (second time proper entry) 0 1 ENTER (a proper end of product entry) All these three exceptions are unchecked and user defined Also handle in case the user enters a nondigit character wia the InputMissmatch exception Example: Enter product and amount pairs: a -5 ENTER Expect to enter an integer please reenter the line. For managers of the campany: If the user enters 2 at the beginning of the execution, then she is a manager. For simplicity do not ask ID of the user to validate her being a manager. Call the managementOpps method For the manager the choices are: 1: see total revenue from all transactions up until now, 2: see total amount of product promotions 3: see total amount of ttransaction promotions 4: total accumulatred points of all customers For each of the action of manager you can define and call a different method in the test class.