CS 211, 004/006
Project 2
due Thursday, October 11th at noon


The objective of this project is to implement a set of classes used to organize a restaurant menu. This exercise skills related to creating classes and extending classes through inheritance. Additionally, it will illustrate a way to work around the limitations of fixed-sized arrays, as well as a more convenient way to configure objects using setter methods.

Overview:

  1. Create the Java class MenuDish, which describes a dish which might show up on a restaurant menu.
  2. Create the class RestaurantMenu, which aggregates a group of MenuDishes, and allows someone to print a menu.
  3. Extend MenuDish to create the child class AdjustableMenuDish, which allows different availability based on the day of the week.
  4. Extend RestaurantMenu to create the child class ResizeableMenu, which allows the internal list of MenuDishes to expand if needed.
  5. Implement the ten mathematical routines described below.
  6. Download and use the tester module to ensure that your program is correct.
  7. Prepare the assignment for submission and submit it
Imagine that you're setting up a web server for a restaurant, and you want to prepare some handler code which will prepare and show the menu for any given day. You know that some of the details may change as you go (the restaurant owner is very fickle, and constantly has new ideas about how to do things), but you have a general idea of what parts you need to do it.

Rules

  1. This project is an individual effort; the Honor Code applies
  2. You may not import any extra functionality besides the default (i.e. System, Math)
  3. The main method will not be tested; you may use it any way you want.
  4. All fields and methods which are not public in the specification must be declared private. This will be verified manually.
  5. You may write your own helper methods, but any methods which are specifically asked for must match exactly (i.e. capitalization of the method name; number and order of the parameters).
MenuDish: (25p)
public class MenuDish

We can begin with a class that represents an item on the menu. This class will store some basics about the item, including name, description, price, category (appetizer, entree, etc). This class will keep track of the following information:

Furthermore, it will implement the following: Notice how all of the setter methods return an instance of the MenuDish class themselves? There's a reason for this. If you call a setter to update the object, and then return a reference to the object itself (return this;), then you can do all initialization in one line:
MenuDish dish = new MenuDish().setName("Mushroom Burger").setDescription("Classic burger covered with portabellas").setCategory(3).setPrice(6.50).setSpiciness(0).setHealthy(false);

Finally, the class should have several constants defined for convenience:

RestaurantMenu: (25p)
public class RestaurantMenu

The RestaurantMenu is an aggregate of a number of MenuDishes. Internally, you should keep an array which you will use to store dishes. Your code should initialze an empty menu, and allow you to add or remove items from the menu, as well as print out the menu. We'll implement the following:

AdjustableMenuDish: (15p)
public class AdjustableMenuDish

It turns out that our intuition was correct, and we do need more functionality from our MenuDish. Now, instead of just keeping track of price, we're going to have different prices for different days (for example, a higher price on weekends). Additionally, we also want to keep track of availability (not every dish is offered every day). Assume that it's enough if we keep track of a week's (7 days) worth of information. Now it matters which day is currently selected (by setDay()). The day starts at zero (a.k.a. MenuDish.MONDAY) by default.

We will declare AdjustableMenuDish as a subclass of MenuDish, since we still want most of the functionality from before. This time, though, we want to add the following methods:

Additionally, we'll probably need to override some of the existing methods to take into account the new 7-day price and availability. Which ones? Hint: which ones would you expect to work with data which relates to the price or availability?

ResizeableMenu: (25p)
public class ResizeableMenu

We've realized that when we create a new menu, we run out of space for new items faster than we expected. We can always allocate a new menu with a much higher upper limit, but we've thought of an even better idea: a menu with an array which resizes itself when it runs out of space.

The RestaurantMenu began with a default list size of 10 (unless we specified something different when we initialized it). We will use the same default of 10 here. This time, however, if we run out of space, we will add 10 more elements to the previous capacity. So basically, if we try to add a new dish, and discover that there's no room for it, we'd create a new list which is 10 elements larger than before, copy everything over from the old list, and replace the old list. This way, we can always be sure we'll have enough space (as long as the computer's memory allows it).

This is very similar to how the built-in ArrayList class works. We will be learning about and using ArrayList before too long, but for this project, we'll be doing it ourselves.

We will use the same RestaurantMenu as before, but we will subclass it to create the ResizeableMenu. In fact, there's very little which needs to be added:

Testing:

Download and use the following to test your code (in addition to the tester jar which you already have):

Grading:

The implementation of each class carries the weight mentioned in each part above (25%, 25%, 15%, and 25%). Half of that score comes from automatic testing, and half comes from manual inspection. 10% will be granted for style (i.e. commenting code, not writing unreadable code), including properly distinguishing which fields and methods should be private.

Partial credit is possible, but hard-coding to avoid test cases will receive an automatic zero on the manual inspection points. Programs which do not compile without modification will receive a zero in most cases.

Submission:

Submission instructions are as follows.

  1. Let xxx be your lab section number (one of 213-220), and let yyyyyyyy be your GMU userid. Create the directory xxx_yyyyyyyy_P2/
  2. Place the files MenuDish.java, RestaurantMenu.java, AdjustableMenuDish.java, and ResizeableMenu.java in the directory you've just created.
  3. Create the file ID.txt in the format shown below, containing your name, userid, G#, lecture section and lab section, and add it to the directory. Your directory should contain five files total.

    Full Name: Donald Knuth
    userID: dknuth
    G#: 00123456
    Lecture section: 004
    Lab section: 213

  4. compress the folder and its contents into a .zip file, and upload the file to Blackboard.