Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Additional code needed:

image text in transcribed

PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your new class BurgerOrder, and click Finish. 3 Inside your newly created class, right-click and choose Insert Code... from the popup menu. public class BurgerOrder f 13 14 15> 16 Navigate Show Javadoc Find Usages Call Hierarchy AF7 Insert Code Fix Imports 4) In the new popup menu that appears, click Add Property... [Note: remember that a property is another term for a class field.] 13 public class BurgerOrder 14 Generate Constructor... Logger... toStringo. Override Method Add Property 16 5) What you will now see is a dialog box that is designed to help you add properties to your class and will even help you write code related to that property Nane sting Type: Sting O package anerae gemer and seter Genarate geter Genrate se Cenerate jvadec Peview private String string + Get the value of string ereturn the value of string public String getstring) return string: Set the value of string 6) Wc're going to create a private integer field called numHamburgers, and initialize i to 0. We also want NetBeans to create a getter and setter for this field, and we' let NetBeans generate the Javadoc for us. Here's what the dialog box looks like when it is filled out for this: private int nunnanburgers ; k Get the value of nunHanbargers Greturn the value of nunHanburgers k/ public int getNunHanburgers) return nunHanburgers; /44 Set the value of nunHanburgers public void setNunhanburgerstint nuntanburgers) Notice that the code Netbeans is going to automatically generate for you is shown in the Preview window. Make sure your dialog box looks like the one above then click OK Note: you may wonder why you'd bother to fill out this dialog box when you could have just typed private int numHamburgers = 0; at the top of your class. But look closely at what NetBeans has done for you. It added two complete new public methods (the getter and the setter) that allow other code to find out and change the value of numHamburgers. It put the field in the proper place at the top of the file. It added all the appropriate curly braces, and the Javadoc comments. That is a lot of typing avoided, and probably lots of errors avoided too. This code isn't perfect, but it's a really good start 7) Modify the setNumHamburgers) method so that if the parameter passed in is less than zero, an error is printed out and the field value is not changed. This would be a good time to pause for a moment and review what just happened. Note how the getters and setters use the parameters that were passed in to set the values of the fields for this class. Later, when we create objects of this class, you'll see how this capability is used. 8) Add three more private fields to this class: int numCheeseburgers, int numVeggieburgers, and int numSodas, following the same process, and initializing each to 0. Note that the code is added wherever your cursor is in the file when you clicked the Insert Code command so if you want all your field definitions grouped together at the beginning of your code you'l have to manually move things around. 9) Repeat step 7 for setNumCheeseburgers, setNumVeggieburgers (, and setNumSodas) 10) Add a private boolean field to the class called orderTOGo, and initialize it to false. Notice that when Netbeans generates a getter for this field, calls it isOrderTOGO , which makes the method more readable, and obvious that it is going to return a boolean 11) Add one more field to this class: a private integer for orderNum. Initialize it to a positive number of your choosing. 12) If necessary, organize the components of your class so they are in the standard order: all the fields at the top and the getters and setters below them. 13) Finally, add a constructor to this class. Right-click in the class (below the fields, but above the first getter/setter method) and choose Insert Code... then select Constructor... from the popup menu. This time there is no dialog box, but a default constructor is added to the top of the class. 14) Modify the constructor so that it takes six parameters, one each for the number of Hamburgers Cheeseburgers, Veggieburgers and sodas to put in the food order, and one boolean parameter that specifies if the order is for takeout, and one for the order number. Inside the constructor, set each field to the appropriate parameter 15) Finally, add a toString ) method to your class. This method is something that you usually add to a new class that specifies how to print out information about the object (so that if the object is passed as the parameter to a system.out.println) call, good information is displayed). To do this, right click at the bottom of the class, after the last getter/setter, and select Insert Code... and then select toString0 from the popup window. What you should see is a dialog pop up that asks you which fields to print out: Select fields to be included in toString0: numCheeseburgers : in numHamburgers: int numVeggieburgers: int numSodas: int orderTOGO: boolean Cancel Generate Leave all the fields selected and click the Generate button 16) NetBcans has created a nice little method for you that prints out all the fields names and their current values, with perfect spacing and commas in between cach override public String toString) return "BurgerOrdert" "numCheeseburgers"numCheeseburgersumHamb Sweet! (The @Override just means that the parent class, java.lang.Object, also has a toString method, but when a BurgerOrder object is printed out, the BurgerOrder.toString( method will be used we' learn more about parent classes, inheritance, and over-riding soon) 17) Time to test your new class. Switch over to Lab5TestProject.java and comment out all the code that does the sound array list. Add the following code to test your new BurgerOrder class: public static void main(String[] args) TODO code application logic here BurgerOrder orderl-new BurgerOrder 3, 5, 4, 10, false, 1; BurgerOrder order2 new BurgerOrder e, , 3, 3, true, 2); BurgerOrder order3 ne BurgerOrder, 1, 0, 2, false, 3); System.out.println order1); System.out.println(order2); System.out.println order3); FileChooser.setMediaPath"/Users/clatulip/Documents/Teaching/Mec Now, run your program to see the information about each new BurgerOrder get printed out Output-LabsTestProject (run) BurgerOrderinunCheeseburgers-5, BurgerOrderinunCheeseburgers=a, nunHamburgers:0, numVeggeburgers-3, nunSodas-3, orde r TOG0=true, orde rNunz2) Burgerorder nunCheeseburgers-1, numHanburgers-1, numveggieburgers-, nunSodas-2, orderTOGO-false, orderNun-3 BUILD SUCCESSFUL (total time: seconds) > nunHamburgers-3, numveggieburgers=4, nunsodas-10, 0rderTOGo-false, 0rderNu 1) 18) Finally, edit this test code and type "orderl" followed by a period to see how NetBeans automatically shows you l the methods that are available to you for BurgerOrder objects BurgerOrder order1new BurgerOrder(3, 5, 4, 10, false, 1); BurgerOrder order2new BurgerOrder 8, 0, 3, 3, true, 2) BurgerOrder order3new BurgerOrder(1, 1, 0, 2, false, 3); order1.| equals (Object obj) getClass() boolearn Class> int int int int Syste ogetNumCheeseburgers) SysteogetNumHamburgers) o getNumSodas ) /getNumVeggieburgers) Filed ogetOrderNum() Array ohashCode( int ching/MediaCo int boolean void void setNumCheeseburgers (int numCheeseburgers) void void void fsetNumVeggieburgers(int numVeggieburgers) voicd void void OsOrderTOGO( ) o notifyALL) setNumSodas (int numSodas) for notify() */ 10 setNumHamburgers (int nunHamburgers) LabETest Project trun) set0rderNum(int orderNum) setorderTOGO (boolean orderT0GO) You'll see all the getters and setters that Netbeans created listed here, along with the toString method, and some other methods like equals(...) and getClass which are inherited from java.lang.Object. So, you've pretty quickly been able to build a whole class. From this menu choose the setNumSodas method, and change the number of sodas in orderl to be 12. Test your code and make sure that the information being printed out about orderl reflects the change. Feel free to play around with some of these other methods to test them out as el 19) Generate the Javadoc for your Lab5TestProject class and look at the BurgerOrder documentation (which should open up automatically in your browser) to make sure it seems reasonable. Make any changes you think are necessary and regenerate if needed. PREV CLAB8 NEXT CLASS MMARY: NESTED FIELD CONSTRI VETHOO DETAIL FIELDICONSTRIMETHOO Class BurgerOrder extende ijavs lang.objeet Constructor Summary Burgeroedertint b, int obeese,iveie, imoda, boolean ToG0,int order) Method Summary Modifier and Type 20) Show your BurgerOrder.java class, the JavaDoc documentation, your test code and your UML diagram to the Professors or TA to get credit for this assignmern Switch Driver and Navigator Part B: Create a FastFoodKitchen class that handles BurgerOrders. (2 points) Objective: To create an ArrayList of BurgerOrder objects that allows orders to be added and removed as they are completed. Draw a UML diagram in the drawing program. 1) Add another class to your Lab5TestProject called FastFoodKitchen (see steps 1 and 2 in Part A for guidance if you don't remember how) 2) At the top of your FastFoodKitchen class, add an ArrayList of BurgerOrder objects called orderList. Make orderList private 3) Using the Insert Code ->Add Property dialog box, add an int field called nextOrderNum, making it both private and static, and have NetBeans generate a getter), but not a setter There is no initial value 4) Add a new private static void method that is called incrementNextOrderNum that does exactly that- adds one to the nextOrderNum field. This must be called cach time after creating a new order, to make sure that no order ever has the same order id number. Why do you think we are telling you to create anincrementNextOrderNum method instead of just having you let NetBcans create a setter method that allows you to change the nextOrderNum field? 5) Create a constructor for FastFoodKitchen that populates orderList with an initial set of three orders using the same numbers of items as the three orders in the test code for Part A orderList.add (new Burgerorder (3, 5, 4, 10, false, getNextorderNum ) )) incrementNextorderNum) You will need to call the getNextOrderNum method to specify the order id number, and you must call incrementNextorderNum after you add cach order 6) Add the following methods to FastFoodKitchen. For all but the last one, you will need to write the code inside the method (we give you the code for the kitchen simulator method, just to save you some time). The bullet points under each tell you what the method must do public int addorder (int ham, int cheese, int veggie, int soda, boolean TOGO) Using the values of the parameters, create a new BurgerOrder, using the next order number available Add this new BurgerOrder to orderList Increment nextOrderNum Return the order id number of the order you just created o o o o public boolean isorderDone (int orderID) Iterate through orderList, checking cach order If there is an order in the list whose order number matches orderID, the order is still in progress, so return false If there isn't an order in the list that matches orderlD, return true o o o private void orderCal1Out (Burgrorder order) o For each possible item in an order (hamburgers, Cheeseburgers, etc.), if there is at least one of these in the order, call out (i.e., print to console) how many of cach item are in the order private void completeSpecificOrder (int orderID) o Find the order in the list with the matching order number o Call out (print to console) that this order is done o If the order is to go, call the 'orderCallOut' method to announce the details of the order o Remove this order from the list private void completeNextorder ) o Find the order at the front of the list (index 0) o Call out (print to console) that this order is done o If the order is to go, call the 'orderCallOut' method to announce the details of the order o Remove this order from the front of the list public int getNumOrdersPending ) o Return the number of orders currently in the orderList Part C: Add a method that will cancel a specific order (1 point) 1) Add the following method to FastFoodKitchen. public boolean cancelOrder (int orderID) o Iterate through orderList, checking cach order o If there is an order in the list whose order number matches orderID, remove the order from the orderList and return true If there isn't an order in the list that matches orderlD, return false o 2) In the Lab5TestProject.java file, make the following changes: Add a new menu option for Cancel an order Add a new case to the switch statement for this new option o o Ask user to enter the order number for the order they want to cancel -Call the cancelOrder method with user entered order number "If the method returns true, display "Your order has been successfully cancelled" Otherwise, display "Sorry, we can't find your order number in the system" Bonus: Add constants to the BurgerOrderClass defining how much each item costs. Add a field to store the cost of the order, along with a getter to retrieve it. Calculate the cost of each order when it is created. Add code so that the user is told the cost of their order when they add it, draw this out in your sketchbook. (1 point) FastFoodKitchen kitchen new FastFoodKitchen Scanner sc new Scanner(System. in); while (kitchen.get Wsee if user wants to add an order System.out.printn Please select from the following menu of options, by typing a number.") System.out.printnt 1. Order food") System.out.printint 2. Check on an order" System.out.printint 3. Show all the orders currently pending."); System.out.printint 4. Do nothing just waiting)") try ( int num sc.nextlnt switch (num) ( case 1 System.out.printin How many hamburgers do you want?) int ham - sc.nextint) System.out.printin How many cheeseburgers do you want?") int cheese sc.nextint System.out.printin How many veggieburgers do you want?") int veggie sc.nextlnt): System.out.printin How many sodas do you want?); int sodas-sc.nextint System.out.printinIs your order to go? (YIN)") char letter sc.next.harAt(0) boolean TOGO false; if (letter- 11 letter-y ) { TOGOtrue int orderNum kitchen.addOrder(ham, cheese, veggie, sodas, TOGO) System.out.printinThank-you. Your order number is" + orderNum) System.out.printin): break case 2: System.out.printin What is your order number?") int order sc.nextint); boolean ready kitchen.isOrderDone(order); if (ready) System.out.printin"Yes, we already called out order number"orde); )else System.out.printin("No, it's not ready, but it should be up soon. Sorry for the wait System.out.printin): break case 3 System.out.printin(kitchen) break; case break default System.out.printin"Sorry, but you need to enter a 1, 2, 3 or a 4") catch (InputMismatchException ime) System.out printin( Sorry, but that wasnt a number."); simulate cooking activity in the kitchen )end while loop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are the attributes of communication?

Answered: 1 week ago

Question

What steps should be taken to address any undesirable phenomena?

Answered: 1 week ago