Write A Complete Java Program Based On The Uml Class Diagram Given In Figure 1 Your Program Should Be Able To Produce T 1 (147.47 KiB) Viewed 26 times
Write a complete Java program based on the UML class diagram given in Figure 1. Your program should be able to produce the output shown in Figure 3. << interface >> Taxable Tax Rate = 0.075 • calcTax(): double Vehicle -type: String << abstract >> Product description: String -price: double + Groceries() + Groceries(String, double) getDescription(): String +getPrice(): double + abstract calcPrice(): double + abstract dispinfo(): String + Vehicle(String, double, String) Food -quantity: double 1.4 +Fruit(String, double, double) purchase Figure 1: UML class diagram Customer -name: String - totalPrice: double -productList Vector Product Number of products purchased: 2 Product 1 (Information for Product 1} Product 2 (Information for Product 2} TOTAL PRICE: RM. + Customer(String) + purchase(Product): void +toString(): String .show(); void + calcProductPurchased(): int ProductApp Implement all the classes with the instance variables (attributes) and methods specified in the diagram. The purpose of each method is as the name implies, and some of them are further explained below. Write the program based on the following tasks: + static main(String); void + static displayMenu(): void (a) Write a class named Customer. The class provides the following instance/ member variables and methods: (11 Marks) (i) Define all the attributes of the class. Note: You need to use the Vector (dynamic array) to declare productList attribute. (1 mark) (ii) Define the constructor with arguments. Initialize all the attributes of the instance with the passed argument and/or zero value. Then, create the object from class Vector that is defined in Task a(i). (1 mark) (iii) Define the toString method. The method returns the following sentence: "<<< (Customer Name)'s shopping list >>>". (1 mark) (iv) Define the cale Product Purchased method. The method returns the number of products purchased by a customer. (1 mark) 2 (v) Define the purchase method. The method is used to add an object from the Product class to the productList array and calculate the total price for all of the products purchased by a customer. The object added to the array represents the product purchased by a customer. (2 marks) (vi) Define the show method. The method is used to display the list and the total commission of products purchased by a customer (if any) in the following format (please refer to the sample output given in Figure 3): (5 marks) (b) Write an interface named Taxable and declare one final static variable and one abstract (1 Mark) method.
(c) Write an abstract superclass named Product. The class provides the constructor with arguments that initialize all the member attributes to the values passed as arguments. It also provides the getDescription method, which returns the value of description member variable, as well as the getPrice method, which returns the value of price member variable. (4 Marks) (d) Write a subclass Vehicle that implements the Taxable interface with the following codes: (8.5 Marks) (i) Define the constructor with arguments that will initialize all of the class's member attributes, including the superclass's attributes. (1.5 marks) (ii) Define the cale Tax method, which will return the tax paid on each product purchased. (1 mark) (iii) Define the calcPrice method, which will return the price of each product purchased, including taxes. (1 mark) (iv) Define the dispInfo method, which will display the product's description and type, price before and after tax in RM, and tax levied in the following format (please refer to the sample output given in Figure 3): (3.5 marks) Description: ???? ???? Type: ???? ???? Price before tax: RM###**.* Price after tax: RM0.00 The tax levied: RM####.## 3 (e) Write a subclass Food with the following codes: (6.5 Marks) (i) Define the constructor with arguments that will initialize all of the class's member attributes, including the superclass's attributes. (1.5 marks) (ii) Define the calePrice method, which will return the price of each product purchased, including taxes. (1 mark) (iii) Define the dispInfo method, which will display the product's description and type, price per kg in RM, quantity and subtotal price in RM in the following format (please refer to the sample output given in Figure 3): (3 marks) Product: ???? ???? Price: RM.## per kg Quantity: 0.0 Subtotal Price: RM##.##
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!