Term Project Goal: To follow the software life cycle, which includes a GUI, that demonstrates the hierachical solution of the Composite Pattern.
Domain Objects Goal: To build the "business" objects of the application first.
Tutorial
Software Life Cycle:
Requirments/Analysis: "What" the system should do. See Narrative and Example Output below.
Design: "How" the system does it. See three-tier architecture: arch.pdf. This design will be implemented in Ex7a, 7b, 7c, 7d.
Implementation: Code in Java.
Validation Test: Verify that the output is correct.
Application Narrative:
The application maintains MenuBooks, which are a collection of Menus. Each Menu is a collection of Recipes. Each Recipe has many Ingredients, and a sequence of preparation Steps. An Ingredient is a particular food Item, with a specified quantity of Units (e.g. 4 cup sugar). An Item has its own base Unit (e.g. oz), along with the number of calories per base Unit.
Note the there is a natural "hierarchy" present, and that each level has "many" children. In Ex7b, this will lead us to using the Composite Design Pattern.
Example MenuBook Output:
MENU BOOK: Menu: Birthday Dinner (DINNER) Recipe: Hamburgers Ingredients: 0.25 lb Hamburger Meat 1.0 regular Hamburger Bun 1.0 slice American Cheese Steps: 1. Grill hamburger meat for 10 minutes 2. After 5 minutes, place on cheese on hamburger 3. After 7 minutes, place top/bottom of bun on grill 4. When done, serve hamburger in bun Total Calories: 950
Note that the example shows ONLY 1 Menu in the MenuBook, ONLY 1 Recipe in the Menu. Normally, there will be MANY, and your testing program will have this. Also, calories are usually listed for individual Recipes but we're going to do total calories for the entire MenuBook as part of the Composite Pattern in Ex7b.
Example Existing Application: Interactive Menu Planner
Note that your application is going to look different and have different functionality than the above.
In this exercise you'll build the Domain Objects for the application. Domain Objects are the object-oriented representation of the "things" inside the application. They often look just like a record (say, a struct in C). Domain Objects are also called business or application objects.
Because this is perhaps your first big project, I'm going to help with the design. Don't worry, there will be plenty of work for you to do.
Assignment
Here is the UML design of the 8 classes that will be used to create Domain Objects: ex7a.pdf
Note in the diagram that there are four "many" relationships using asterick (*): MenuBook has many FoodMenus, FoodMenus have many Recipes, Recipes have many Ingredients and many Steps. This should make you think about Vectors or ArrayLists as containers. But don't do anything for now about this until we get the Composite Pattern in Ex7b.
Note the four "singular" relationships: FoodMenu has "a" MenuType, Ingredient has a Unit and an Item, Item has a Unit. These will appear as an object declaration, e.g.
public class Ingredient { private Item item; ... }
MenuType should be an "enum" class for BREAKFAST, LUNCH, DINNER, i.e. the type of FoodMenu.
Ingredient's getCalories() is tricky. Ingredient x has a certain quantity of a certain Unit of Item y (say, 4 cups sugar). Item y has a number of calories (say, 100) as measured in perhaps a different Unit (say, 10 oz, where 10 is the factor). So getCalories() cannot just multiply the quantity (4) times the number of calories (100) in Item y. The key is that Unit has a factor (say, a cup is 8 oz). So now you have the numbers 4, 100, 10, 8. What are you going to do? You should work this out because it affects your getCalories().
Code these 8 public classes on the directory: planner/gui/domain/. This means you must establish the same directory structure.
Note that MenuBook already exists and contains a testing program of the Birthday Dinner (along with the x, y example just above). The class is complete but has some code that is commented out. Instructions show what to uncomment for ex7a, or ex7b.
MenuBook's first line is:
package planner.gui.domain;
Also, don't worry about the code inside of toString() in the various classes until you see how it will be used in ex7b. Just put something reasonable for now.
As you write your code, document it. Note that MenuBook already has a "javadoc" comment.
Here is a simple Javadoc Tutorial which also provides other references.
Document your 8 classes using the above standards.
Ex7a-Test1
Edit MenuBook and uncomment the specified code for Ex7a-Test1 in the constructor. Compile, run, and javadoc:
cd ex7 javac planner/gui/domain/MenuBook.java java planner/gui/domain/MenuBook javadoc planner/*.java planner/gui/*.java planner/gui/domain/*.java
Ex7a-Test1 Output
x : 320 ing1: 800 ing2: 100 ing3: 50
Did you get the correct result? Note that x is for the 4, 100, 10, 8 example above.
Here is the current javadoc: planner/allclasses-noframe.html
Turn-In: planner/gui/domain directory structure with your 8 classes: .zip, unix account (or send the 8 classes and instructor will put on this directory structure).