PFA
Program #1 Decorated Pizzas 10% Due: 10/22/2018 Starting files: • prog2_starting_files.zip Your program must work using the provided input files which should recreate the examples shown below. Obtain your input using the util.Keyboard class and make sure that your input gets read in correctly using < as we have done numerous times in class. i will not grade your program if i cannot obtain the input using a text file. i will be writing new input files using the same format to grade your programs. your classes should also work with my gui (provided in the zip), as this ensures that all of your methods are designed as described below. a pizza is composed of a crust (with tomato sauce and cheese) and toppings. crust a small pizza costs $5.99, a medium is $7.99, and a large is $9.99. a hand- tossed crust is an additional $0.50, and a deep dish pan crust is an additional $1.00. write a crustsize enum [s(5.99), m(7.99), and l(9.99)] and a crusttype enum [thin(0.00), hand(0.50), and pan(1.00)]. place your enums in crustenum.java. both enums should have cost methods. write a crust class with a constructor that accepts and sets the crust size and type and provide a crustcost method. write a tostring method to report the state of the crust. write getcrust (returns "thin", "hand", or "pan") and getsize (returns a char 's', 'm', or 'l'). toppings the toppings and their respective abbreviation and cost is as follows: • pepperoni p 0.99 • sausage s 0.99 • onions o 0.79 • greenpeppers g 0.69 • mushrooms m 0.79 a pizza also has toppings, such as pepperoni, sausage, mushrooms, peppers, and/or onions. one way to handle all of the various combinations of toppings that can be ordered is to have a boolean for each possible topping in a pizza class. however, this can cause headaches if new toppings are added to the menu. therefore, you will use the decorator design pattern to handle the toppings. each topping will have an associated class (i.e. a pepperoni class) that will extend an abstract decoratedpizza class. the decoratedpizza class itself has a private decoratedpizza instance variable next_pizza_item, a no- argument default constructor (next_pizza_item set to null), a constructor that accepts a decoratedpizza (and sets next_pizza_item to this decoratedpizza), and three methods: • public double pizzacost() //get the cost from the "next_pizza_item" decoratedpizza • public string tostring() //get the state of the "next_pizza_item" decoratedpizza • public string getimage() //get the abbreviation of the "next_pizza_item" decoratedpizza (the topping abbreviation is used to obtain the correct pizza image) whenever a topping is added to the pizza, pass the current decoratedpizza to the constructor for the associated topping (which in turn calls the appropriate constructor in the parent class). this allows a decoratedpizza with an arbitrary number of toppings to be built up by wrapping, or decorating, each topping on top of the current decoratedpizza (essentially a linked list). for example, if pepperoni is added as a first topping, then the decoratedpizza minus the pepperoni is the instance variable stored in the pepperoni class. when the pizza cost is required, get the pizza cost from the parent class (which gets the cost from the "next_pizza_item") and add the cost of pepperoni to it, returning the total cost including pepperoni. when the image of the pizza is required, get the image file (a string) from the instance variable, and append a "p" to it. the tostring method works similarly. thus, if a new topping is added to the menu, a new class is written for that topping, and all of the current code can be used without modification. complete classes for pepperoni, onions, sausage, greenpeppers, and mushrooms. pizza the pizza class also extends decoratedpizza, but it has only the crust as an instance variable, so the pizza class will call the default constructor in its parent class (decoratedpizza). the pizza class represents the "base" pizza (with no toppings). the pizzacost and tostring methods will use the crust instance variable, and the getimage method appends an s, m, or l to the string representing the image file. the size of the pizza will then be the first letter added to the image file string. the final image file name will look like mpos.jpg for a medium pizza with pepperoni, onions, and sausage. this means that the pepperoni topping was selected first, followed by onions and then sausage. the gui will append the ".jpg" for you. pizza builder there is a lot of input validation that must be done in this program. you will use the builder design pattern to handle input validation. the builder design pattern places all of the input validation in a separate class, making the core classes much more readable. pizzabuilder will need to keep track of some information as instance variables. one of these is the top link in the decoratedpizza (the head of the linked list). use as few instance variables as possible (i will count off for bad designs). write the following methods in pizzabuilder: • protected void buildpizza() //create a crust and a pizza using that crust based on the user's specifications (the pizza is now ready for toppings) • public pizzabuilder() //start with a small, thin pizza with no toppings as the default • public boolean setsize(char try_size) //returns true if the input was valid ("s" or "small", etc., not case sensitive, use the string charat method to get the first character) • public boolean setcrust(string try_crust) //("thin", "hand", or "pan", not case sensitive) • public void addtopping(char topping_char) //compare the topping abbreviation to topping_char to determine which topping to add (using void here is convenient for the pizzadriver, ignore invalid abbreviations) • public decoratedpizza pizzadone() //return the final decoratedpizza and reset to the default pizza if another pizza is desired specialty pizzas • ham h 0.89 • pineapple a 0.89 extend pizzabuilder and override the buildpizza() method (use super) to add the toppings required to create various specialty pizzas like meatlover's, veggielover's and hawaiian (ham and pineapple). note that you are only adding new behavior in the overridden method. these classes should be very short. pizza driver write a driver, pizzadriver.java, to allow the user to order an indefinite number of pizzas. place pizzadriver in the pizza package. this is done by creating a pizzabuilder, which will return the completed decoratedpizza when pizzadone is called. include the following methods: • private static int menu() //show the menu choices, wait for and return the valid selection • private static void requestsize(pizzabuilder pizza_builder) //request the crust size, wait for a valid response confirmation from pizzabuilder • private static void requestcrust(pizzabuilder pizza_builder) //request the crust type, wait for a valid response confirmation from pizzabuilder • private static void requesttoppings(pizzabuilder pizza_builder) //ask for toppings until done indicated (invalid toppings are ignored) • private static void showorder(decoratedpizza dec_pizza) //display the pizza and its total cost • public static void main (string[] args) //allow the user to order multiple pizzas if desired, call the other methods, track total cost and number of pizzas after a pizza has been specified, display the order details and the cost for the pizza. format your cost output to display two decimal places. use the decimalformat class (java.text.decimalformat). prompt for another pizza and either restart the order process (you will need to create a new pizzabuilder object), or stop execution, based on the user response. when the user is done ordering, report the number of pizzas ordered and the total cost of all the pizzas ordered. pizza factory the individual topping classes really just hardcode in the values for that topping. this is not a good class design. a much better class would allow these values to be passed to the constructor. improve your design by using a pizzatopping class and a pizzatoppingfactory class (with static methods and no constructor) instead of individual topping classes (but don't delete your previous classes, i want to see them). new toppings can be added to the menu by adding methods to the pizzatoppingfactory class rather than writing a new class. • pizzatopping constructor: public pizzatopping(decoratedpizza pizza_component, string topping_string, string topping_letter, double topping_cost) • pizzatoppingfactory example method: public static decoratedpizza addpepperoni(decoratedpizza dec_pizza) //create a pizzatopping with the pepperoni values and add it to the passed decoratedpizza, returning the result pizzadiscount • pizzadiscount constructor: public pizzadiscount(decoratedpizza pizza_component, string msg, double discount) //discount is assumed to be between 0.0 and 1.0 a pizzadiscount extends decoratedpizza adjusting the final cost of the pizza by the discount. add an adddiscount method to pizzabuilder. adjust addtopping to make sure that a topping is not added after the discount. that is, a pizzatopping can only be connected to other pizzatoppings or a pizza (use instanceof). pizzabuilder really helps manage this complexity, keeping this code out of the other classes. in pizzadriver, ask the user if they are senior citizens. if so, apply a 10% discount to the order. pizzafee • pizzafee constructor: public pizzafee(decoratedpizza pizza_component, string msg, double fee) a pizzafee extends decoratedpizza, adding on a flat fee to the total order at the very end. add an addfee method to pizzabuilder. adjust adddiscount so that pizzadiscounts can only be connected to other pizzadiscounts, pizzatoppings, or pizza. as pizzadriver will probably ask for these items where appropriate, i will look at your code to make sure this check is performed. in pizzadriver, ask the user if they want delivery. if so, add a $2.50 delivery fee to the order. would you like to order a pizza (y/n)? y 1. meat lover's 2. veggie lover's 3. hawaiian 4. build your own select from the above: 4 what size pizza (s/m/l)? zwhat size pizza (s/m/l)? m what type of crust (thin/hand/pan)? thin (p)epperoni,(o)nions,(g)reen peppers,(s)ausage,(m)ushrooms,(d)one as="" we="" have="" done="" numerous="" times="" in="" class.="" i="" will="" not="" grade="" your="" program="" if="" i="" cannot="" obtain="" the="" input="" using="" a="" text="" file.="" i="" will="" be="" writing="" new="" input="" files="" using="" the="" same="" format="" to="" grade="" your="" programs.="" your="" classes="" should="" also="" work="" with="" my="" gui="" (provided="" in="" the="" zip),="" as="" this="" ensures="" that="" all="" of="" your="" methods="" are="" designed="" as="" described="" below.="" a="" pizza="" is="" composed="" of="" a="" crust="" (with="" tomato="" sauce="" and="" cheese)="" and="" toppings.="" crust="" a="" small="" pizza="" costs="" $5.99,="" a="" medium="" is="" $7.99,="" and="" a="" large="" is="" $9.99.="" a="" hand-="" tossed="" crust="" is="" an="" additional="" $0.50,="" and="" a="" deep="" dish="" pan="" crust="" is="" an="" additional="" $1.00.="" write="" a="" crustsize="" enum="" [s(5.99),="" m(7.99),="" and="" l(9.99)]="" and="" a="" crusttype="" enum="" [thin(0.00),="" hand(0.50),="" and="" pan(1.00)].="" place="" your="" enums="" in="" crustenum.java.="" both="" enums="" should="" have="" cost="" methods.="" write="" a="" crust="" class="" with="" a="" constructor="" that="" accepts="" and="" sets="" the="" crust="" size="" and="" type="" and="" provide="" a="" crustcost="" method.="" write="" a="" tostring="" method="" to="" report="" the="" state="" of="" the="" crust.="" write="" getcrust="" (returns="" "thin",="" "hand",="" or="" "pan")="" and="" getsize="" (returns="" a="" char="" 's',="" 'm',="" or="" 'l').="" toppings="" the="" toppings="" and="" their="" respective="" abbreviation="" and="" cost="" is="" as="" follows:="" •="" pepperoni="" p="" 0.99="" •="" sausage="" s="" 0.99="" •="" onions="" o="" 0.79="" •="" greenpeppers="" g="" 0.69="" •="" mushrooms="" m="" 0.79="" a="" pizza="" also="" has="" toppings,="" such="" as="" pepperoni,="" sausage,="" mushrooms,="" peppers,="" and/or="" onions.="" one="" way="" to="" handle="" all="" of="" the="" various="" combinations="" of="" toppings="" that="" can="" be="" ordered="" is="" to="" have="" a="" boolean="" for="" each="" possible="" topping="" in="" a="" pizza="" class.="" however,="" this="" can="" cause="" headaches="" if="" new="" toppings="" are="" added="" to="" the="" menu.="" therefore,="" you="" will="" use="" the="" decorator="" design="" pattern="" to="" handle="" the="" toppings.="" each="" topping="" will="" have="" an="" associated="" class="" (i.e.="" a="" pepperoni="" class)="" that="" will="" extend="" an="" abstract="" decoratedpizza="" class.="" the="" decoratedpizza="" class="" itself="" has="" a="" private="" decoratedpizza="" instance="" variable="" next_pizza_item,="" a="" no-="" argument="" default="" constructor="" (next_pizza_item="" set="" to="" null),="" a="" constructor="" that="" accepts="" a="" decoratedpizza="" (and="" sets="" next_pizza_item="" to="" this="" decoratedpizza),="" and="" three="" methods:="" •="" public="" double="" pizzacost()="" get="" the="" cost="" from="" the="" "next_pizza_item"="" decoratedpizza="" •="" public="" string="" tostring()="" get="" the="" state="" of="" the="" "next_pizza_item"="" decoratedpizza="" •="" public="" string="" getimage()="" get="" the="" abbreviation="" of="" the="" "next_pizza_item"="" decoratedpizza="" (the="" topping="" abbreviation="" is="" used="" to="" obtain="" the="" correct="" pizza="" image)="" whenever="" a="" topping="" is="" added="" to="" the="" pizza,="" pass="" the="" current="" decoratedpizza="" to="" the="" constructor="" for="" the="" associated="" topping="" (which="" in="" turn="" calls="" the="" appropriate="" constructor="" in="" the="" parent="" class).="" this="" allows="" a="" decoratedpizza="" with="" an="" arbitrary="" number="" of="" toppings="" to="" be="" built="" up="" by="" wrapping,="" or="" decorating,="" each="" topping="" on="" top="" of="" the="" current="" decoratedpizza="" (essentially="" a="" linked="" list).="" for="" example,="" if="" pepperoni="" is="" added="" as="" a="" first="" topping,="" then="" the="" decoratedpizza="" minus="" the="" pepperoni="" is="" the="" instance="" variable="" stored="" in="" the="" pepperoni="" class.="" when="" the="" pizza="" cost="" is="" required,="" get="" the="" pizza="" cost="" from="" the="" parent="" class="" (which="" gets="" the="" cost="" from="" the="" "next_pizza_item")="" and="" add="" the="" cost="" of="" pepperoni="" to="" it,="" returning="" the="" total="" cost="" including="" pepperoni.="" when="" the="" image="" of="" the="" pizza="" is="" required,="" get="" the="" image="" file="" (a="" string)="" from="" the="" instance="" variable,="" and="" append="" a="" "p"="" to="" it.="" the="" tostring="" method="" works="" similarly.="" thus,="" if="" a="" new="" topping="" is="" added="" to="" the="" menu,="" a="" new="" class="" is="" written="" for="" that="" topping,="" and="" all="" of="" the="" current="" code="" can="" be="" used="" without="" modification.="" complete="" classes="" for="" pepperoni,="" onions,="" sausage,="" greenpeppers,="" and="" mushrooms.="" pizza="" the="" pizza="" class="" also="" extends="" decoratedpizza,="" but="" it="" has="" only="" the="" crust="" as="" an="" instance="" variable,="" so="" the="" pizza="" class="" will="" call="" the="" default="" constructor="" in="" its="" parent="" class="" (decoratedpizza).="" the="" pizza="" class="" represents="" the="" "base"="" pizza="" (with="" no="" toppings).="" the="" pizzacost="" and="" tostring="" methods="" will="" use="" the="" crust="" instance="" variable,="" and="" the="" getimage="" method="" appends="" an="" s,="" m,="" or="" l="" to="" the="" string="" representing="" the="" image="" file.="" the="" size="" of="" the="" pizza="" will="" then="" be="" the="" first="" letter="" added="" to="" the="" image="" file="" string.="" the="" final="" image="" file="" name="" will="" look="" like="" mpos.jpg="" for="" a="" medium="" pizza="" with="" pepperoni,="" onions,="" and="" sausage.="" this="" means="" that="" the="" pepperoni="" topping="" was="" selected="" first,="" followed="" by="" onions="" and="" then="" sausage.="" the="" gui="" will="" append="" the="" ".jpg"="" for="" you.="" pizza="" builder="" there="" is="" a="" lot="" of="" input="" validation="" that="" must="" be="" done="" in="" this="" program.="" you="" will="" use="" the="" builder="" design="" pattern="" to="" handle="" input="" validation.="" the="" builder="" design="" pattern="" places="" all="" of="" the="" input="" validation="" in="" a="" separate="" class,="" making="" the="" core="" classes="" much="" more="" readable.="" pizzabuilder="" will="" need="" to="" keep="" track="" of="" some="" information="" as="" instance="" variables.="" one="" of="" these="" is="" the="" top="" link="" in="" the="" decoratedpizza="" (the="" head="" of="" the="" linked="" list).="" use="" as="" few="" instance="" variables="" as="" possible="" (i="" will="" count="" off="" for="" bad="" designs).="" write="" the="" following="" methods="" in="" pizzabuilder:="" •="" protected="" void="" buildpizza()="" create="" a="" crust="" and="" a="" pizza="" using="" that="" crust="" based="" on="" the="" user's="" specifications="" (the="" pizza="" is="" now="" ready="" for="" toppings)="" •="" public="" pizzabuilder()="" start="" with="" a="" small,="" thin="" pizza="" with="" no="" toppings="" as="" the="" default="" •="" public="" boolean="" setsize(char="" try_size)="" returns="" true="" if="" the="" input="" was="" valid="" ("s"="" or="" "small",="" etc.,="" not="" case="" sensitive,="" use="" the="" string="" charat="" method="" to="" get="" the="" first="" character)="" •="" public="" boolean="" setcrust(string="" try_crust)="" ("thin",="" "hand",="" or="" "pan",="" not="" case="" sensitive)="" •="" public="" void="" addtopping(char="" topping_char)="" compare="" the="" topping="" abbreviation="" to="" topping_char="" to="" determine="" which="" topping="" to="" add="" (using="" void="" here="" is="" convenient="" for="" the="" pizzadriver,="" ignore="" invalid="" abbreviations)="" •="" public="" decoratedpizza="" pizzadone()="" return="" the="" final="" decoratedpizza="" and="" reset="" to="" the="" default="" pizza="" if="" another="" pizza="" is="" desired="" specialty="" pizzas="" •="" ham="" h="" 0.89="" •="" pineapple="" a="" 0.89="" extend="" pizzabuilder="" and="" override="" the="" buildpizza()="" method="" (use="" super)="" to="" add="" the="" toppings="" required="" to="" create="" various="" specialty="" pizzas="" like="" meatlover's,="" veggielover's="" and="" hawaiian="" (ham="" and="" pineapple).="" note="" that="" you="" are="" only="" adding="" new="" behavior="" in="" the="" overridden="" method.="" these="" classes="" should="" be="" very="" short.="" pizza="" driver="" write="" a="" driver,="" pizzadriver.java,="" to="" allow="" the="" user="" to="" order="" an="" indefinite="" number="" of="" pizzas.="" place="" pizzadriver="" in="" the="" pizza="" package.="" this="" is="" done="" by="" creating="" a="" pizzabuilder,="" which="" will="" return="" the="" completed="" decoratedpizza="" when="" pizzadone="" is="" called.="" include="" the="" following="" methods:="" •="" private="" static="" int="" menu()="" show="" the="" menu="" choices,="" wait="" for="" and="" return="" the="" valid="" selection="" •="" private="" static="" void="" requestsize(pizzabuilder="" pizza_builder)="" request="" the="" crust="" size,="" wait="" for="" a="" valid="" response="" confirmation="" from="" pizzabuilder="" •="" private="" static="" void="" requestcrust(pizzabuilder="" pizza_builder)="" request="" the="" crust="" type,="" wait="" for="" a="" valid="" response="" confirmation="" from="" pizzabuilder="" •="" private="" static="" void="" requesttoppings(pizzabuilder="" pizza_builder)="" ask="" for="" toppings="" until="" done="" indicated="" (invalid="" toppings="" are="" ignored)="" •="" private="" static="" void="" showorder(decoratedpizza="" dec_pizza)="" display="" the="" pizza="" and="" its="" total="" cost="" •="" public="" static="" void="" main="" (string[]="" args)="" allow="" the="" user="" to="" order="" multiple="" pizzas="" if="" desired,="" call="" the="" other="" methods,="" track="" total="" cost="" and="" number="" of="" pizzas="" after="" a="" pizza="" has="" been="" specified,="" display="" the="" order="" details="" and="" the="" cost="" for="" the="" pizza.="" format="" your="" cost="" output="" to="" display="" two="" decimal="" places.="" use="" the="" decimalformat="" class="" (java.text.decimalformat).="" prompt="" for="" another="" pizza="" and="" either="" restart="" the="" order="" process="" (you="" will="" need="" to="" create="" a="" new="" pizzabuilder="" object),="" or="" stop="" execution,="" based="" on="" the="" user="" response.="" when="" the="" user="" is="" done="" ordering,="" report="" the="" number="" of="" pizzas="" ordered="" and="" the="" total="" cost="" of="" all="" the="" pizzas="" ordered.="" pizza="" factory="" the="" individual="" topping="" classes="" really="" just="" hardcode="" in="" the="" values="" for="" that="" topping.="" this="" is="" not="" a="" good="" class="" design.="" a="" much="" better="" class="" would="" allow="" these="" values="" to="" be="" passed="" to="" the="" constructor.="" improve="" your="" design="" by="" using="" a="" pizzatopping="" class="" and="" a="" pizzatoppingfactory="" class="" (with="" static="" methods="" and="" no="" constructor)="" instead="" of="" individual="" topping="" classes="" (but="" don't="" delete="" your="" previous="" classes,="" i="" want="" to="" see="" them).="" new="" toppings="" can="" be="" added="" to="" the="" menu="" by="" adding="" methods="" to="" the="" pizzatoppingfactory="" class="" rather="" than="" writing="" a="" new="" class.="" •="" pizzatopping="" constructor:="" public="" pizzatopping(decoratedpizza="" pizza_component,="" string="" topping_string,="" string="" topping_letter,="" double="" topping_cost)="" •="" pizzatoppingfactory="" example="" method:="" public="" static="" decoratedpizza="" addpepperoni(decoratedpizza="" dec_pizza)="" create="" a="" pizzatopping="" with="" the="" pepperoni="" values="" and="" add="" it="" to="" the="" passed="" decoratedpizza,="" returning="" the="" result="" pizzadiscount="" •="" pizzadiscount="" constructor:="" public="" pizzadiscount(decoratedpizza="" pizza_component,="" string="" msg,="" double="" discount)="" discount="" is="" assumed="" to="" be="" between="" 0.0="" and="" 1.0="" a="" pizzadiscount="" extends="" decoratedpizza="" adjusting="" the="" final="" cost="" of="" the="" pizza="" by="" the="" discount.="" add="" an="" adddiscount="" method="" to="" pizzabuilder.="" adjust="" addtopping="" to="" make="" sure="" that="" a="" topping="" is="" not="" added="" after="" the="" discount.="" that="" is,="" a="" pizzatopping="" can="" only="" be="" connected="" to="" other="" pizzatoppings="" or="" a="" pizza="" (use="" instanceof).="" pizzabuilder="" really="" helps="" manage="" this="" complexity,="" keeping="" this="" code="" out="" of="" the="" other="" classes.="" in="" pizzadriver,="" ask="" the="" user="" if="" they="" are="" senior="" citizens.="" if="" so,="" apply="" a="" 10%="" discount="" to="" the="" order.="" pizzafee="" •="" pizzafee="" constructor:="" public="" pizzafee(decoratedpizza="" pizza_component,="" string="" msg,="" double="" fee)="" a="" pizzafee="" extends="" decoratedpizza,="" adding="" on="" a="" flat="" fee="" to="" the="" total="" order="" at="" the="" very="" end.="" add="" an="" addfee="" method="" to="" pizzabuilder.="" adjust="" adddiscount="" so="" that="" pizzadiscounts="" can="" only="" be="" connected="" to="" other="" pizzadiscounts,="" pizzatoppings,="" or="" pizza.="" as="" pizzadriver="" will="" probably="" ask="" for="" these="" items="" where="" appropriate,="" i="" will="" look="" at="" your="" code="" to="" make="" sure="" this="" check="" is="" performed.="" in="" pizzadriver,="" ask="" the="" user="" if="" they="" want="" delivery.="" if="" so,="" add="" a="" $2.50="" delivery="" fee="" to="" the="" order.="" would="" you="" like="" to="" order="" a="" pizza="" (y/n)?="" y="" 1.="" meat="" lover's="" 2.="" veggie="" lover's="" 3.="" hawaiian="" 4.="" build="" your="" own="" select="" from="" the="" above:="" 4="" what="" size="" pizza="" (s/m/l)?="" zwhat="" size="" pizza="" (s/m/l)?="" m="" what="" type="" of="" crust="" (thin/hand/pan)?="" thin="" (p)epperoni,(o)nions,(g)reen=""> as we have done numerous times in class. i will not grade your program if i cannot obtain the input using a text file. i will be writing new input files using the same format to grade your programs. your classes should also work with my gui (provided in the zip), as this ensures that all of your methods are designed as described below. a pizza is composed of a crust (with tomato sauce and cheese) and toppings. crust a small pizza costs $5.99, a medium is $7.99, and a large is $9.99. a hand- tossed crust is an additional $0.50, and a deep dish pan crust is an additional $1.00. write a crustsize enum [s(5.99), m(7.99), and l(9.99)] and a crusttype enum [thin(0.00), hand(0.50), and pan(1.00)]. place your enums in crustenum.java. both enums should have cost methods. write a crust class with a constructor that accepts and sets the crust size and type and provide a crustcost method. write a tostring method to report the state of the crust. write getcrust (returns "thin", "hand", or "pan") and getsize (returns a char 's', 'm', or 'l'). toppings the toppings and their respective abbreviation and cost is as follows: • pepperoni p 0.99 • sausage s 0.99 • onions o 0.79 • greenpeppers g 0.69 • mushrooms m 0.79 a pizza also has toppings, such as pepperoni, sausage, mushrooms, peppers, and/or onions. one way to handle all of the various combinations of toppings that can be ordered is to have a boolean for each possible topping in a pizza class. however, this can cause headaches if new toppings are added to the menu. therefore, you will use the decorator design pattern to handle the toppings. each topping will have an associated class (i.e. a pepperoni class) that will extend an abstract decoratedpizza class. the decoratedpizza class itself has a private decoratedpizza instance variable next_pizza_item, a no- argument default constructor (next_pizza_item set to null), a constructor that accepts a decoratedpizza (and sets next_pizza_item to this decoratedpizza), and three methods: • public double pizzacost() //get the cost from the "next_pizza_item" decoratedpizza • public string tostring() //get the state of the "next_pizza_item" decoratedpizza • public string getimage() //get the abbreviation of the "next_pizza_item" decoratedpizza (the topping abbreviation is used to obtain the correct pizza image) whenever a topping is added to the pizza, pass the current decoratedpizza to the constructor for the associated topping (which in turn calls the appropriate constructor in the parent class). this allows a decoratedpizza with an arbitrary number of toppings to be built up by wrapping, or decorating, each topping on top of the current decoratedpizza (essentially a linked list). for example, if pepperoni is added as a first topping, then the decoratedpizza minus the pepperoni is the instance variable stored in the pepperoni class. when the pizza cost is required, get the pizza cost from the parent class (which gets the cost from the "next_pizza_item") and add the cost of pepperoni to it, returning the total cost including pepperoni. when the image of the pizza is required, get the image file (a string) from the instance variable, and append a "p" to it. the tostring method works similarly. thus, if a new topping is added to the menu, a new class is written for that topping, and all of the current code can be used without modification. complete classes for pepperoni, onions, sausage, greenpeppers, and mushrooms. pizza the pizza class also extends decoratedpizza, but it has only the crust as an instance variable, so the pizza class will call the default constructor in its parent class (decoratedpizza). the pizza class represents the "base" pizza (with no toppings). the pizzacost and tostring methods will use the crust instance variable, and the getimage method appends an s, m, or l to the string representing the image file. the size of the pizza will then be the first letter added to the image file string. the final image file name will look like mpos.jpg for a medium pizza with pepperoni, onions, and sausage. this means that the pepperoni topping was selected first, followed by onions and then sausage. the gui will append the ".jpg" for you. pizza builder there is a lot of input validation that must be done in this program. you will use the builder design pattern to handle input validation. the builder design pattern places all of the input validation in a separate class, making the core classes much more readable. pizzabuilder will need to keep track of some information as instance variables. one of these is the top link in the decoratedpizza (the head of the linked list). use as few instance variables as possible (i will count off for bad designs). write the following methods in pizzabuilder: • protected void buildpizza() //create a crust and a pizza using that crust based on the user's specifications (the pizza is now ready for toppings) • public pizzabuilder() //start with a small, thin pizza with no toppings as the default • public boolean setsize(char try_size) //returns true if the input was valid ("s" or "small", etc., not case sensitive, use the string charat method to get the first character) • public boolean setcrust(string try_crust) //("thin", "hand", or "pan", not case sensitive) • public void addtopping(char topping_char) //compare the topping abbreviation to topping_char to determine which topping to add (using void here is convenient for the pizzadriver, ignore invalid abbreviations) • public decoratedpizza pizzadone() //return the final decoratedpizza and reset to the default pizza if another pizza is desired specialty pizzas • ham h 0.89 • pineapple a 0.89 extend pizzabuilder and override the buildpizza() method (use super) to add the toppings required to create various specialty pizzas like meatlover's, veggielover's and hawaiian (ham and pineapple). note that you are only adding new behavior in the overridden method. these classes should be very short. pizza driver write a driver, pizzadriver.java, to allow the user to order an indefinite number of pizzas. place pizzadriver in the pizza package. this is done by creating a pizzabuilder, which will return the completed decoratedpizza when pizzadone is called. include the following methods: • private static int menu() //show the menu choices, wait for and return the valid selection • private static void requestsize(pizzabuilder pizza_builder) //request the crust size, wait for a valid response confirmation from pizzabuilder • private static void requestcrust(pizzabuilder pizza_builder) //request the crust type, wait for a valid response confirmation from pizzabuilder • private static void requesttoppings(pizzabuilder pizza_builder) //ask for toppings until done indicated (invalid toppings are ignored) • private static void showorder(decoratedpizza dec_pizza) //display the pizza and its total cost • public static void main (string[] args) //allow the user to order multiple pizzas if desired, call the other methods, track total cost and number of pizzas after a pizza has been specified, display the order details and the cost for the pizza. format your cost output to display two decimal places. use the decimalformat class (java.text.decimalformat). prompt for another pizza and either restart the order process (you will need to create a new pizzabuilder object), or stop execution, based on the user response. when the user is done ordering, report the number of pizzas ordered and the total cost of all the pizzas ordered. pizza factory the individual topping classes really just hardcode in the values for that topping. this is not a good class design. a much better class would allow these values to be passed to the constructor. improve your design by using a pizzatopping class and a pizzatoppingfactory class (with static methods and no constructor) instead of individual topping classes (but don't delete your previous classes, i want to see them). new toppings can be added to the menu by adding methods to the pizzatoppingfactory class rather than writing a new class. • pizzatopping constructor: public pizzatopping(decoratedpizza pizza_component, string topping_string, string topping_letter, double topping_cost) • pizzatoppingfactory example method: public static decoratedpizza addpepperoni(decoratedpizza dec_pizza) //create a pizzatopping with the pepperoni values and add it to the passed decoratedpizza, returning the result pizzadiscount • pizzadiscount constructor: public pizzadiscount(decoratedpizza pizza_component, string msg, double discount) //discount is assumed to be between 0.0 and 1.0 a pizzadiscount extends decoratedpizza adjusting the final cost of the pizza by the discount. add an adddiscount method to pizzabuilder. adjust addtopping to make sure that a topping is not added after the discount. that is, a pizzatopping can only be connected to other pizzatoppings or a pizza (use instanceof). pizzabuilder really helps manage this complexity, keeping this code out of the other classes. in pizzadriver, ask the user if they are senior citizens. if so, apply a 10% discount to the order. pizzafee • pizzafee constructor: public pizzafee(decoratedpizza pizza_component, string msg, double fee) a pizzafee extends decoratedpizza, adding on a flat fee to the total order at the very end. add an addfee method to pizzabuilder. adjust adddiscount so that pizzadiscounts can only be connected to other pizzadiscounts, pizzatoppings, or pizza. as pizzadriver will probably ask for these items where appropriate, i will look at your code to make sure this check is performed. in pizzadriver, ask the user if they want delivery. if so, add a $2.50 delivery fee to the order. would you like to order a pizza (y/n)? y 1. meat lover's 2. veggie lover's 3. hawaiian 4. build your own select from the above: 4 what size pizza (s/m/l)? zwhat size pizza (s/m/l)? m what type of crust (thin/hand/pan)? thin (p)epperoni,(o)nions,(g)reen peppers,(s)ausage,(m)ushrooms,(d)one>