Goals
Students will demonstrate their ability to use ArrayLists by writing program for a restaurant menu.
Skills
- ArrayLists
- For Each loops
Program Details
Write a program for a restaurant menu. Your program that create an ArrayList of menu items. The main program will populate 4 different menu items with two different constructors. It will modify the items and search the menu items for certain ingredients. It will output the information to the console.
- Menu Item class
This class needs the following:- Variables (all private)
- String: Menu item name
- Float: Cost of the menu item
- ArrayList of Ingredients
- Methods
- Constructors Methods: Two constructor methods
- One instantiates class variables by passing them directly in. Pass the ArrayList of ingredients in.
- The other asks the user to input everything.
- Accessors
- Getters
- Each variable needs a method to return the value of the variable.
- Pre-generated ones from Eclipse are fine.
- A containsIngredient method
- Returns whether or not the menu item contains an ingredient.
- Returns a Boolean
- Passes in the name of an ingredient to search for.
- Getters
- Mutator Methods
- Setters: three total, one for each variable
- Pass the values directly in. The user does not need to enter the new ingredient.
- Each variable needs a setter to set the variable to a new value.
- These methods should report that the value has been changed from the initial to the final value.
- An addIngredient method
- Passes in an ingredient as a parameter.
- Adds the ingredient to the list of ingredients.
- Reports that the new ingredient has been added.
- A removeIndredient method
- Passes in an ingredient as a parameter.
- Removes the ingredient to the list of ingredients.
- Reports that the ingredient has been removed.
- Setters: three total, one for each variable
- toString
- This method will output the menu item name, menu item cost, number of ingredients, and a list of the ingredients.
- You do not need an ingredientsToString method because you can print an ArrayList directly.
- Constructors Methods: Two constructor methods
- Variables (all private)
- Main program
- This class will create an ArrayList of 4 Menu Items.
- Both constructor methods need to be used.
- Your main program will need to create an ArrayList of ingredients to be able to pass the list directly in for your one constructor .
- Modify each menu item.
- Each item needs to be modified at least once using one of the mutator methods.
- Each mutator method (5 total) needs to be used at least once. The 3 Setters and 2 Mutatores (add and remove ingredient) .
- Contains Ingredient
- The main program will search through all menu items for a specific ingredient using the containsIngredient written for the class.
- If it finds the ingredient, it will add the word “organic” to the name of the ingredient. .
- Keep the order of the ingredients the same.
- For example:
- Search for the word “flour”
- Original list: sugar, flour, salt, butter, eggs.
- Final list: sugar, organic flour, salt, butter, eggs.
- Output to the console the initial and final values of each menu item using the toString method.
- This class will create an ArrayList of 4 Menu Items.
Resources
Java Textbook
Chapter 5: Conditionals and Loops
CS Awesome Website
Bill Barnum's AP Computer Science A videos
AP College Board test prep videos
AP College Board: Introduction to and Traversing ArrayLists
AP College Board: ArrayList Methods