Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
AP Computer Science I Java Unit Lab Assignment # 09 The Multi-Inheritance Program Assignment Purpose: This assignment has multiple goals. You need to demonstrate your knowledge of composition and inheritance. You will be writing software in support of a Dessert Shoppe which sells candy by the pound, cookies by the dozen, ice cream, and sundaes (ice cream with a topping). Your software will be used for the checkout system. To do this, you will implement an inheritance hierarchy of classes derived from a DessertItem super class. The Candy, Cookie, and IceCream classes will be derived from the DessertItem class. The Sundae class will be derived from the IceCream class. The DessertItem Class The DessertItem class is a superclass from which specific types of DessertItems can be derived. It contains only one data member, a name. The DessertItem class methods should include: 2 constructors (default, one that accepts and sets name), accessor method, mutator method, toString method and a getCost() method (this is an overridden method because the method of determining the costs varies based on the type of item). The Derived Classes All of the classes which are derived from the DessertItem class must define two constructors. Please see the additional attributes that are needed for each class below to determine the parameters for the various constructors. Each class will implement the overridden method getCost( ) and a toString method. Each derived class should be implemented by creating a file with the correct name, eg., Candy.java. The Candy class should be derived from the DessertItem class. A Candy item has a weight and a price per pound which are used to determine its cost. For example, 2.30 lbs.of fudge @ .89 /lb. = 205 cents. The cost should be rounded to the nearest cent. The Cookie class should be derived from the DessertItem class. A Cookie item has a number and a price per dozen which are used to determine its cost. For example, 4 cookies @ 399 cents /dz. = 133 cents. The cost should be rounded to the nearest cent. The IceCream class should be derived from the DessertItem class. An IceCream item simply has a cost. The Sundae class should be derived from the IceCream class. The cost of a Sundae is the cost of the IceCream plus the cost of the topping. Exposure Java 2007 Chapter IX Lab Assignment Page 1 09-28-07 The Driver Class It allows a user to enter the type of the DessertItem. The appropriate text fields are then enabled so that the user can enter the name and other information for the item. All monetary amounts must be entered as an integer number of cents, ie., 100 instead of 1.00. The Total option displays a receipt which includes an 8% tax amount and clears the “cash register” in preparation for the next transaction. Menu needs to loop. DessertItem order = new DessertItem( ); Dessert Menu 1. 2. 3. 4. 5. 6. Candy Ice Cream Cookie Sundae Display Total Cost Quit order = new IceCream("Strawberry Ice Cream",145); order = new Sundae("Vanilla Ice Cream",105, 50); order = new Candy("Gummy Worms", 133, 89); order = new Cookie("Chocolate Chip Cookies", 4, 399); Example: case 1: String type = utilbl.getS(“Enter type of candy”); int weight = utilbl.getI(“Enter number of lbs”); int price = utilbl.getI(“Enter price per lbs”); order = new Candy(type, weight, price); case 5: After each order display: The item order, total cost of item, tax amount and total Due. EXTRA CREDIT (10 points): Create a method: public static String cents2dollarsAndCents(int cents) Receives an amount in cents and returns the amount as a String in dollar/cent format. For example: pass in 355, returns $3.55 Exposure Java 2007 Chapter IX Lab Assignment Page 2 09-28-07