5.6. Studio: Restaurant Menu Continued

We began designing and implementing our Menu and MenuItem classes in the last studio. Let’s continue working on these classes by adding some methods.

5.6.1. Design

To review, here are the details you have from the restaurant owner:

  1. The menu consists of several menu items.

  2. Each menu item has a price, description, and category (appetizer, main course, or dessert).

  3. It should be possible to display whether or not a menu item is new.

  4. The app should know when the menu was last updated, so visitors can see that the restaurant is constantly changing and adding exciting new items.

Based on these details, you need to include some instance methods:

  1. A way to add and remove menu items from the menu.

  2. A way to tell if a menu item is new.

  3. A way to tell when the menu was last updated.

  4. A way to print out both a single menu item as well as the entire menu.

  5. A way to determine whether or not two menu items are equal.

Starting with pen and paper (or your favorite notes application on your laptop), sketch out the methods that you need to add to these classes. List the method names and access levels, along with the types of all input and return parameters. Also, consider whether any methods should be static.

5.6.2. Share Your Design

Once you have sketched out your methods, pair with a classmate and take turns presenting your designs. Class design can be subjective, so it’s important to properly think and talk through your choices before coding.

While your partner is presenting their design, ask questions about why they made the decisions they did. Consider other use cases that might come up, and see if their design fits with those.

5.6.3. Implementation

  1. In IntelliJ, open your Restaurant Menu project. Open the terminal in IntelliJ and create a branch in your repository for your Lesson 4 Studio solution. For the studio, make sure all of your work is in that branch.

  2. Within the restaurant package, add the methods you designed to your Menu and MenuItem classes.

  3. Create a class called Restaurant, and add a public static void main(String[] args) method.

  4. Use the main method to test your classes:

    1. Create several items and add them to a menu.

    2. Print the entire, updated menu to the screen.

    3. Print an individual menu item to the screen.

    4. Delete an item from a menu, then reprint the menu.

5.6.4. Bonus Mission

If a user tries to add an item that is already on the menu, print a message that warns the user about the duplicate. Also, prevent the duplicate from being added to the menu.

5.6.5. Submitting Your Work

In the previous studio, you should have created a repository on GitHub for your restaurant project.

Since you just modified that project in this studio, commit your changes and push them up to the same repository. However, you must still submit the URL for your repository on Canvas.