question archive Instructions for Challenge #2 As we learned from the module on inheritance and polymorphism, a super class should contain all the instance variables that are common to all subclasses
Subject:Computer SciencePrice:13.86 Bought8
Instructions for Challenge #2 As we learned from the module on inheritance and polymorphism, a super class should contain all the instance variables that are common to all subclasses. The subclasses inherit the superclass variables and methods, and can have additional variables & methods, and can override methods from the superclass. A superclass can also implement an interface, which forces it to code specific methods. Overview of Project Find the zipped Netbeans project on Canvas, which contains a skeleton of the driver and domain classes, GrandparentTradition, ParentTradition and ChildrenTradition. See the UML diagram below for the details of each class. The driver class will do 3 main tasks: 1.) Read a text file & create the appropriate object for each record, depending on the record type 2.) Add each object to a single arrayList that can hold all 3 types of objects (grandparent, parent, and child objects) 3.) Once the arrayList is fully populated, process each object by calling its polymorphic methods to: a. Display how each object celebrates the holidays b. Tabulates & displays the costs of the celebrations. Domain Classes: Carefully look at the superclass called GrandparentsTradition which implements the interface called Celebratable. Then, define all of its subclasses making sure to reference the superclass methods where appropriate (e.g. constructor, toString, and tabulateCosts ). ? Define the appropriate instance variables in each of the subclasses (see UML diagram). ? Define the appropriate constructor in each of the subclasses, taking advantage of inheritance. ? Define the getters & setters in each of the subclasses. ? Define the tabulateCosts() and the celebrate() polymorphic methods in each of the subclasses. Be sure to reference superclass versions of the tabulateCosts() method: o Costs at the Grandparent level are just an estimate of 10 x the cost per serving o Costs at the Parent level are the same as the costs at the Grandparent level plus the costs of the drinks and desserts per guest that the parents invited o Costs at the Children level are the same as the costs at the Parent level plus the costs of the movie rental. ? Define the toString() method of each subclass, making sure to also reference the superclass .toString(). ? See the examples of the output in the last couple of pages in this document. Driver Class: In the main method you must define the arrayList that will be returned from the createTraditions() method. Then, you must pass that arrayList as an argumen to the celebrateHolidays() method. ? = createTraditions(); celebrateHolidays(?); In the createTraditions() method you must finish the code to: 1.) Add the arrayList as a return type to the method and return it at the end of the method. 2.) Within a loop read each field in each record & depending on the first letter in the record, create a Grandparent, Parent, or Children object. 3.) Within the same loop add each object created to an arrayList. Be sure to carefully the select the data type of the arrayList to be able to hold all 3 types of classes. 4.) Once the entire file has been read, close it. In the celebrateHolidays() method you must: 1.) Add the arrayList as a parameter to the method. 2.) Write a loop that will iterate through the entire arrayList a. Within the loop, call the polymorphic methods that will cause each object to display how they celebrate the holidays and what is the cost of doing so. The toString() method should follow the formats below for each class: For GrandparentTradition objects: We grandparents like to celebrate the holidays like _______ during the ______ holiday season at the _____. We eat _____ as the main dish, with __ side dishes. We like to eat in the _____. The food is from a ____ source. The cost per serving is about ____ For a typical gathering of 10, we will spend ____ For ParentTradition objects: We parents like to celebrate the holidays like ______ during the ____ holiday season at the ____. We eat _____ as the main dish, with __ side dishes. We like to eat in the _____. The food is from a _____ source. The cost per serving is about ___ We ALSO like to invite at least __ friends over to our house after our meal to eat _____ for dessert, and drink _____. We pay ____ for each dessert, and ____ for each drink. For a typical gathering of __, we will spend ___ plus the costs of desserts & drinks per guest: ____ For ChildrenTradition objects: We children like to celebrate the holidays like ____ during the ____ holiday season at the ____. We eat ___ as the main dish, with __ side dishes. We like to eat in the ___. The food is from a ___ source. The cost per serving is about ___ We ALSO like to invite at least __ friends over to our house after our meal to eat _____ for dessert, and drink ____. We pay ___ for each dessert, and ____ for each drink. AND, before and after our meal we like to play _____. We also like watching holiday movies like _______ which usually cost about _____ At bedtime, we like to read holiday stories like _________. For a typical gathering of ___, we will spend ____ plus the costs of desserts & drinks per guest: ____ plus the cost of a movie: ____ Given the following records in the input text file for the project: g Thanksgiving Autumn 6:00pm turkey 8 dining_room 20.00 home-cooked g Christmas Winter 1:00pm pork 6 outdoor_patio 30.00 catered g Easter Spring 3:00pm ham 7 dining_room 25.00 pot_luck g Fourth_of_July Summer 1:00pm ribs 5 picnic 15.00 barbeque p Thanksgiving Autumn 7:00pm chicken 6 outdoor_patio 20.00 home-cooked 12 pumpkin_pie apple_cider 3.00 4.00 p Christmas Winter 5:00pm ham 10 dining_room 35.00 home-cooked 10 flan egg_nog 3.25 1.95 p Easter Spring 6:00pm mac-n-cheese 4 dining_room 20.00 pot_luck 8 carrot_cake orange_juice 3.25 2.50 p Fourth_of_July Summer 11:00am sandwiches 3 picnic 15.00 catered 15 apple_pie lemonade 3.50 1.50 c Thanksgiving Autumn 5:00pm ham 10 living_room 17.00 pot_luck 25 pecan_pie wine 5.00 6.00 Checkers Pilgrims_in_America Coming_to_America 3.25 c Christmas Winter 3:00pm turkey 8 dining_room 28.00 catered 12 peppermint_ice_cream champagne 4.25 6.50 Chess Twas_the_Night_Before_Christmas It's_a_Wonderful_Life 3.00 c Easter Spring 4:00pm lamb 6 dining_room 32.00 home-cooked 10 egg_custard tomato_juice 4.25 1.50 Easter_Egg_Hunt Peter_Rabbit The_Greatest_Story_Ever_Told 4.50 c Fourth_of_July Summer 10:00am pancakes 3 outdoor_patio 12.00 home-cooked 12 peaches mimosa 2.50 7.50 volleyball An_American_Tail Independence_Day 3.75 The following is the output of the project: We grandparents like to celebrate the holidays like Thanksgiving during the Autumn holiday season at the 6:00pm. We eat turkey as the main dish, with 8 side dishes. We like to eat in the dining_room. The food is from a home-cooked source. The cost per serving is about $20.00 For a typical gathering of 10, we will spend 200.00 We grandparents like to celebrate the holidays like Christmas during the Winter holiday season at the 1:00pm. We eat pork as the main dish, with 6 side dishes. We like to eat in the outdoor_patio. The food is from a catered source. The cost per serving is about $30.00 For a typical gathering of 10, we will spend 300.00 We grandparents like to celebrate the holidays like Easter during the Spring holiday season at the 3:00pm. We eat ham as the main dish, with 7 side dishes. We like to eat in the dining_room. The food is from a pot_luck source. The cost per serving is about $25.00 For a typical gathering of 10, we will spend 250.00 We grandparents like to celebrate the holidays like Fourth_of_July during the Summer holiday season at the 1:00pm. We eat ribs as the main dish, with 5 side dishes. We like to eat in the picnic. The food is from a barbeque source. The cost per serving is about $15.00 For a typical gathering of 10, we will spend 150.00 We parents like to celebrate the holidays like Thanksgiving during the Autumn holiday season at the 7:00pm. We eat chicken as the main dish, with 6 side dishes. We like to eat in the outdoor_patio. The food is from a home-cooked source. The cost per serving is about $20.00 We ALSO like to invite at least 12 friends over to our house after our meal to eat pumpkin_pie for dessert, and drink apple_cider. We pay $3.00 for each dessert, and 4.00 for each drink. For a typical gathering of 10, we will spend 200.00 plus the costs of desserts & drinks per guest: $84.00 We parents like to celebrate the holidays like Christmas during the Winter holiday season at the 5:00pm. We eat ham as the main dish, with 10 side dishes. We like to eat in the dining_room. The food is from a home-cooked source. The cost per serving is about $35.00 We ALSO like to invite at least 10 friends over to our house after our meal to eat flan for dessert, and drink egg_nog. We pay $3.25 for each dessert, and 1.95 for each drink. For a typical gathering of 10, we will spend 350.00 plus the costs of desserts & drinks per guest: $52.00 (continued on next page) We parents like to celebrate the holidays like Easter during the Spring holiday season at the 6:00pm. We eat mac-n-cheese as the main dish, with 4 side dishes. We like to eat in the dining_room. The food is from a pot_luck source. The cost per serving is about $20.00 We ALSO like to invite at least 8 friends over to our house after our meal to eat carrot_cake for dessert, and drink orange_juice. We pay $3.25 for each dessert, and 2.50 for each drink. For a typical gathering of 10, we will spend 200.00 plus the costs of desserts & drinks per guest: $46.00 We parents like to celebrate the holidays like Fourth_of_July during the Summer holiday season at the 11:00am. We eat sandwiches as the main dish, with 3 side dishes. We like to eat in the picnic. The food is from a catered source. The cost per serving is about $15.00 We ALSO like to invite at least 15 friends over to our house after our meal to eat apple_pie for dessert, and drink lemonade. We pay $3.50 for each dessert, and 1.50 for each drink. For a typical gathering of 10, we will spend 150.00 plus the costs of desserts & drinks per guest: $75.00 We children like to celebrate the holidays like Thanksgiving during the Autumn holiday season at the 5:00pm. We eat ham as the main dish, with 10 side dishes. We like to eat in the living_room. The food is from a pot_luck source. The cost per serving is about $17.00 We ALSO like to invite at least 25 friends over to our house after our meal to eat pecan_pie for dessert, and drink wine. We pay $5.00 for each dessert, and 6.00 for each drink. AND, before and after our meal we like to play Checkers. We also like watching holiday movies like Coming_to_America which usually cost about $3.25. At bedtime, we like to read holiday stories like Pilgrims_in_America. For a typical gathering of 10, we will spend 170.00 plus the costs of desserts & drinks per guest: $275.00 plus the cost of a movie: $3.25 We children like to celebrate the holidays like Christmas during the Winter holiday season at the 3:00pm. We eat turkey as the main dish, with 8 side dishes. We like to eat in the dining_room. The food is from a catered source. The cost per serving is about $28.00 We ALSO like to invite at least 12 friends over to our house after our meal to eat peppermint_ice_cream for dessert, and drink champagne. We pay $4.25 for each dessert, and 6.50 for each drink. AND, before and after our meal we like to play Chess. We also like watching holiday movies like It's_a_Wonderful_Life which usually cost about $3.00. At bedtime, we like to read holiday stories like Twas_the_Night_Before_Christmas. For a typical gathering of 10, we will spend 280.00 plus the costs of desserts & drinks per guest: $129.00 plus the cost of a movie: $3.00 We children like to celebrate the holidays like Easter during the Spring holiday season at the 4:00pm. We eat lamb as the main dish, with 6 side dishes. We like to eat in the dining_room. The food is from a home-cooked source. The cost per serving is about $32.00 We ALSO like to invite at least 10 friends over to our house after our meal to eat egg_custard for dessert, and drink tomato_juice. We pay $4.25 for each dessert, and 1.50 for each drink. AND, before and after our meal we like to play Easter_Egg_Hunt. We also like watching holiday movies like The_Greatest_Story_Ever_Told which usually cost about $4.50. At bedtime, we like to read holiday stories like Peter_Rabbit. For a typical gathering of 10, we will spend 320.00 plus the costs of desserts & drinks per guest: $57.50 plus the cost of a movie: $4.50 We children like to celebrate the holidays like Fourth_of_July during the Summer holiday season at the 10:00am. We eat pancakes as the main dish, with 3 side dishes. We like to eat in the outdoor_patio. The food is from a home-cooked source. The cost per serving is about $12.00 We ALSO like to invite at least 12 friends over to our house after our meal to eat peaches for dessert, and drink mimosa. We pay $2.50 for each dessert, and 7.50 for each drink. AND, before and after our meal we like to play volleyball. We also like watching holiday movies like Independence_Day which usually cost about $3.75. At bedtime, we like to read holiday stories like An_American_Tail. For a typical gathering of 10, we will spend 120.00 plus the costs of desserts & drinks per guest: $120.00 plus the cost of a movie: $3.75 Parents Tradition UNROERED UNREGISTE Grandparents Tradition INREGISTERED UN Celebratable UNREGIST-holidayame: String NREGISTERED UN -holiday season: String +celebrate(: String implements -timeOiDay Celebration Sering +tabulateCosts: String INREGISTERED UN -mainDishName: String UNREGISTERED UNREGISTE numberOfSide Dishes in NREGISTERED UN UNREGISTERED UNREGISTE Source Sting -cost Mealdouble INREGISTERED UN UNREGISTERED UNREGISTE +Grandparents Tradition(String. String, String. String, int, String, double, String) NREGISTERED UN UNREGISTERED UNREGISTE-setters NREGISTERED UN UNREGISTERED UNREGISTE-celebrate(); String NREGISTERED UN tabulate Costs(): String UNREGISTERED UNREGISTEL ? NREGISTERED UN UNREGISTERED UNREGISTERED UNREGISTERT UNREGISTERED UNREGISTERED UN UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UN UNREGISTERED UNREGISTERED UNREGIST extends UNREGISTERED UNREGISTERED UN UNREGISTERED UNREGISTERED UNREGISTER UNREGISTERED UNREGISTERED UN UNREGISTERED UNREGISTERED UNREGISTER UNREGISTERED UNREGISTERED UN UNREGISTERED UNRE TERED UN UNREGISTERED UNR numberlinvited:int STERED UN UNREGISTERED UNR traditionalDrink String STERED UN UNREGISTERED UNR-CostPerDrink: double STERED UN UNREGISTERED UNRetters Parents Tradition(String. String. String, String, int String, double String, int, String. String, double double) STERED UN UNREGISTERED UNR-toString0 String STERED UN UNREGISTERED UNR-celebrate : String tabulateCosts(): String STERED UN UNREGISTERED UNREGISTERED UNREGISTERAUNREGISTERED UNREGISTERED UN UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UN UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UN UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UN UNREGISTEREDE Children Tradition - holiday Game: String UNREGISTERED holiday Storybook String UNREGISTERED COOlivovie double UNREGISTERED :Children Tradition(String. String, String. Sering, int, String, double, String, int, String. String, double double, String. String, String, double UN UNREGISTERED Settersió UN HoString String UNREGISTERED celebrate String tabulateCosts: String UN UNREGISTEREN UN UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UNREGISTERED UN