Question: Part A: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we

Part A: 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. 1. Create a new project in called FastFoodKitchen with a main class. Remember that the main class is the class we will use to add code that will be executed when we run the project. We will refer to this class as the main class but you are free to call it any valid Java class name (e.g., Main). For a review on writing classes and objects review Unit 5 of the CS Awesome textbook. 2. Create a new class. Call your new class BurgerOrder, and click Finish. 3. Now start adding instance variable definitions to your BurgerOrder class. Click the blank line below public class BurgerOrder{. Create a private integer field called numHamburgers, and initialize it to 0. 4. We also want to add a getter and setter methods for this field. Add the standard getter method that returns the value of numHamburgers. 5. For the setter method we want it to check that if the parameter passed in is less than zero, an error message is printed out and the field value is not changed. If it is not less than zero, then change the field value to the parameter passed. 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, youll see how this capability is used. 6. Add three more private fields to this class: int numCheeseburgers, int numVeggieburgers, and int numSodas, following the same process, and initializing each to 0. 7. Add getters and setters similar to what we did for the numHamburgers field. 8. Add a private boolean field to the class called orderToGo, and initialize it to false. Getter methods for fields with a boolean data type dont normally follow the getter methods naming convention. They are commonly named with a pattern that starts with the word is followed by the field name. For example, for our orderToGo field the getter method would be isOrderToGo(), which makes the method more readable, and obvious that it is going to return a boolean (equivalent to the answer to a yes/no question). 9. Add the isOrderToGo() and setOrderToGo(...) methods for the orderToGo field. 10. Add one more field to this class: a private integer called orderNum. Initialize it to a positive number of your choosing and add the getter and setter methods for it as well. 11. Make sure to 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. 12. Add a constructor to this class, below the fields, but above the first getter/setter method. This constructor should take six parameters, one 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.

13. Time to test your new class. Switch over to the main class and add the following code to the main method to test your new BurgerOrder class: 14. Now, run your program to see the information about each new BurgerOrder get printed out: 15. Finally, edit this test code and type order1 followed by a period to see how it automatically shows you all the methods that are available to you for BurgerOrder objects: 16. Youll see all the getters and setters created listed here, along withsome other methods like the toString(), equals(...) and getClass() which are inherited from java.lang.Object. So, youve pretty quickly been able to build a whole class. From this menu choose the setNumSodas() method, and change the number of sodas in order1 to be 12. Test your code and make sure that the information being printed out about order1 reflects the change. Feel free to play around with some of these other methods to test them out as well. Part B: Create an ArrayList of BurgerOrder objects and methods to manage it 1. Add another class to your project called FastFoodKitchen. Note that if your main class was called FastFoodKitchen you will need to use a different name for this step (e.g., FastFoodKitchenSimulation) or you can change the name of the main class for this project (e.g., Main)

2. At the top of your FastFoodKitchen class, add an ArrayList of BurgerOrder objects called orderList. Make orderList private. 3. Add a second field that is an integer called nextOrderNum, making it both private and static Can you guess why we would want this method to be static? 4. Add a getter method for the nextOrderNum field. We do not need a setter method for this field. 5. Add a new private static method that is called incrementNextOrderNum() that does exactly that adds one to the nextOrderNum field. This method doesnt need to return anything (void). This method must be called each time after creating a new order, to make sure that no order has the same order id number. 6. 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. There are several ways to accomplish this step. You can either have a no- parameter constructor where you create three BurgerOrder instances and add them to orderList or you can create a constructor that takes in three BurgerOrder objects as parameters that get added to orderList inside that constructor. Regardless of how you complete this step you will need to reference the nextOrderNum field either directly (if youre creating the orders in the constructor) or using the getNextOrderNum() method if you create the objects and pass them in as arguments. Remember that this is a static method so you can call it using the class name - FastFoodKitchen.getNextOrderNum(). You need to do this to specify the order id number when you need to create a BurgerOrder object and you must call incrementNextOrderNum() afterwards to update the field value. 7. Now we are ready to add methods to handle placing and managing orders in a fast food kitchen. Add the following methods to FastFoodKitchen. 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 number of the order you just created public boolean cancelLastOrder() If there are orders in the list Remove the last order Decrement nextOrderNum Return true to indicate that an order has been canceled If there are no orders in the list return false to indicate the list is empty. public int getNumOrdersPending() Return the number of orders currently in the orderList 8. Add Javadoc for each of the methods in the class. 9. Now, switch over to your main class and comment out the code from Part A. Copy and paste this code snippet

FastFoodKitchen kitchen = new FastFoodKitchen(); Scanner sc = new Scanner(System.in);

while (kitchen.getNumOrdersPending() != 0) { // see what the user wants to do System.out.println("Please select from the following menu of options, by typing a number:"); System.out.println("\t 1. Order food"); System.out.println("\t 2. Cancel last order"); System.out.println("\t 3. Show number of orders currently pending."); System.out.println("\t 4. Exit");

int num = sc.nextInt(); switch (num) {

case 1: System.out.println("How many hamburgers do you want?"); int ham = sc.nextInt(); System.out.println("How many cheeseburgers do you want?"); int cheese = sc.nextInt(); System.out.println("How many veggieburgers do you want?"); int veggie = sc.nextInt(); System.out.println("How many sodas do you want?"); int sodas = sc.nextInt(); System.out.println("Is your order to go? (Y/N)"); char letter = sc.next().charAt(0); boolean TOGO = false; if (letter == 'Y' || letter == 'y') { TOGO = true; } int orderNum = kitchen.addOrder(ham, cheese, veggie, sodas, TOGO); System.out.println("Thank-you. Your order number is " + orderNum); System.out.println(); break; case 2: boolean ready = kitchen.cancelLastOrder(); if (ready) { System.out.println("Thank you. The last order has been canceled"); } else { System.out.println("Sorry. There are no orders to cancel."); } System.out.println(); break; case 3: System.out.println("There are " + kitchen.getNumOrdersPending() + " pending orders"); break; case 4: System.exit(0); break; default: System.out.println("Sorry, but you need to enter a 1, 2, 3 or a 4");

} // end switch statements

} // end while loop

into the main() method. You can delete or comment out the code we have from Part A. Read through the code to get a sense for what it is doing. Note that you will need to add the import statement for the Scanner class as we are using it in the code snippet you just copied. 10. Run your program and test the different menu options to make sure that your methods are working. You should be able to add a new order, cancel the last order, get the number of pending orders and orders. Fix any bugs you find. 11. Generate the Javadoc to make sure that your FastFoodKitchen class is well documented. 12. Part C: Use ArrayList methods to manipulate the contents of an array list by referencing specific elements

1. Add the following methods to FastFoodKitchen. public boolean isOrderDone(int orderID) Iterate through orderList, checking each 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 isnt an order in the list that matches orderID, return true public boolean cancelOrder(int orderID) Iterate through orderList, checking each order. If there is an order in the list whose order number matches orderID, remove the order from the orderList and return true If there isnt an order in the list that matches orderID, return false 2. Now we need to update the main class by adding menu options for the methods we added. Make the following changes to the main() method: Add a new menu option for checking on an order Add a new case to the switch statement for this new option Ask user to enter the order number for the order they want to check on Call the isOrderDone method with user entered order number If the method returns true, display No order was found If the method return false, display Your order in being prepared Add a new menu option for canceling an order Add a new case to the switch statement for this new option 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 cant find your order number in the system 3. Run your project and test to make sure that your new methods are working. You should be able to check on or cancel an existing order. Make sure that the other methods still work as expected. Fix any bugs you find.

I only need the final code of the project, not each section please. I'm running into so many errors doing this myself so I just need a guide to see what I'm doing wrong.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!