Question:
Discuss the objectives for this week and together design a simple system that involves at least two objects interacting. One of these objects must represent a food item of some kind (e.g. a cupcake or hamburger). The other object should represent a stall that the food item is sold from. Your system must involve at least two (2) associated objects that satisfy these rules:
The food item object must have some kind of dynamic status (for example you might represent the current status of the food item in terms of price, ingredients, or freshness). It must be possible to change the status of the food item using appropriate methods; Your food item object must have a unique automatically generated ID that is created when you create each food item object; The two objects are associated so one class has a reference attribute to identify the other object (for example a stall contains an array of food items – each stored as particular food item objects).
A farmer’s market contains a variety of stalls. Each stall has a name, an owner and can sell a variety of food items according to its classification e.g. a hamburger stall might sell hamburgers, soft drink and chips, a cupcake stall might sell cupcakes and coffee. Every food item has detailed information stored about it such as the wholesale costs and retail costs. Food items can be hot or cold and come in small, medium or large.
Write a short description using words for your system that explains how the 2 objects interact with each other. Ensure you have described the interaction in terms of messages or actions between the objects. Show your tutor to verify your design before proceeding. Discuss the methods required for each class design so that your objects are capable of the desired behaviour.
1. For each method, answer the following questions, What does this method do (e.g. does it produce output or change the object state)? When is this method valid (e.g. does the object have to be in a special state for this method to be performed)? Plan a process to validate that the method is working as desired (e.g. create some specific test cases) Write pseudo code to specify the logic and decision making required in this method
2. Draw a UML class diagram for each class (you may do this on paper or by using Enterprise Architect (available in the resources section on Moodle, see appendix)) Programming
2 – Lab 3 Semester 1, 2018 Page 3 of 10 3. If the previous step was completed using Enterprise Architect, you can generate code stubs for your two classes with set and get methods to be filled in, otherwise, you need to create the code yourself in a new Eclipse project
4. Take the code stubs generated in the previous step and create your own project in Eclipse.
5. Fill in code in the get/set methods 6. Create a toString method for each class
7. Write the code for each method, based on pseudo code already written. Ensure you check that objects are in the correct valid state for each method.
8. Write a simple test driver class to test your classes are working
9. Using the debugger mode in Eclipse, check that the states are being updated appropriately on your objects (you will be asked to demonstrate this use as part of exercise 2 of this document. This demonstration will take place in the laboratory in week 4)
10. Demonstrate to your tutor that your code works
As you conceptualise your system, it may assist you to consider a similar system involving students at a TAFE college enrolling into a Course. The enrolment phases include 5 possible status options for a student: applied, enrolled, completed, graduated, cancelled. When a student applies to the TAFE program, they are given a unique student number. The first student (ever) who is entered into the system is given the number 293142, subsequently, each student who applies is given the next available student number. Student numbers are always even numbers. As part of the TAFE program, students may be enrolled into a number of courses. Each course instance is allocated a teacher and has a list of enrolled students.
Exercise 2 – Demonstration to be performed individually (5.5 marks) Using examples from the code you wrote, (4 x 0.5 + 2 x 0.25 marks each = 2.5 marks) Explain the difference between public and private; Explain the principles of encapsulation and information hiding; Describe and relate the terms: public interface, information hiding; Explain the significance of the ‘static’ modifier; Describe your chosen test cases; Explain the results of your testing. Demonstrate that you can use the debugger to your tutor by showing (3 marks) use of Eclipse’s debugging tools to set breakpoints, inspect variables, and step through code to observe the behaviour of code to detect errors.
Answer:
Main Menu1: View stalls.
0: Exit.
Enter now… 1
List of stalls
1: ChockoMania(ID: 131).
2: Stacy’s Burger Shop(ID: 140).
3: Chicken King(ID: 300).
0: Main menu.
Enter now… 2
Stall Details
NamStall Id: 140
Name: Stacy’s Burger Shop
Owner: Stacy Smith
Category: Snacks
Foods offered
Food Id: 415
Food Name: Ham Burger
Food Price: 8.5
Food Ingredients: Fresh Bread, Ham Slices, Green Salad, Cheese
Food Status: Hot
Food Id: 881
Food Name: Chicken Burger
Food Price: 7.0
Food Ingredients: Fresh Bread, Chicken Salami, Green Salad, Mayoniese
Food Status: Hot
Food Id: 380
Food Name: Veg Burger
Food Price: 6.0
Food Ingredients: Paneer, Green Salad, Capcicum, Mayoniese, Cheese Slices
Food Status: Normal/Hot
Update Price
Enter Food ID to edit Price of food.
Enter 0 to go back to Stall menu
Enter now…. 881
Enter the new price:
7.5
Price for Chicken Burger has been updated!
Update
Price
Enter Food ID to edit Price of food.
Enter 0 to go back to Stall menu
Enter now…. 0
List of stalls
1: ChockoMania(ID: 131).
2: Stacy’s Burger Shop(ID: 140).
3: Chicken King(ID: 300).
0: Main menu.
Enter now… 2
Stall Details
NamStall Id: 140
Name: Stacy’s Burger Shop
Owner: Stacy Smith
Category: Snacks
Foods offered
Food Id: 415
Food Name: Ham Burger
Food Price: 8.5
Food Ingredients: Fresh Bread, Ham Slices, Green Salad, Cheese
Food Status: Hot
Food Id: 881
Food Name: Chicken Burger
Food Price: 7.5
Food Ingredients: Fresh Bread, Chicken Salami, Green Salad, Mayoniese
Food Status: Hot
Food Id: 380
Food Name: Veg Burger
Food Price: 6.0
Food Ingredients: Paneer, Green Salad, Capcicum, Mayoniese, Cheese Slices
Food Status: Normal/Hot
Update Price
Enter Food ID to edit Price of food.
Enter 0 to go back to Stall menu
Enter now…. 0
List of stalls
1: ChockoMania(ID: 131).
2: Stacy’s Burger Shop(ID: 140).
3: Chicken King(ID: 300).
0: Main menu.
Enter now… 3
Stall Details
NamStall Id: 300
Name: Chicken King
Owner: Jason Macmillan
Category: Lunch/Dinner
Foods offered
Food Id: 784
Food Name: Steak Noodles
Food Price: 12.5
Food Ingredients: Noodles, Chicken, Soup, Green Salad
Food Status: Hot
Food Id: 850
Food Name: Crab
Food Price: 15.0
Food Ingredients: Fresh crab, Garlic Sauce, Vegetables
Food Status: Hot/Normal
Food Id: 165
Food Name: Sweet and sour Lamb
Food Price: 18.5
Food Ingredients: Lamb, Red Sauce, Manchurian spices
Food Status: Hot
Update Price
Enter Food ID to edit Price of food.
Enter 0 to go back to Stall menu
Enter now…. 1569
Food ID does not exist in this stall! Try again.
Update Price
Enter Food ID to edit Price of food.
Enter 0 to go back to Stall menu
Enter now…. 165
Enter the new price:
14.65
Price for Sweet and sour Lamb has been updated!
Update Price
Enter Food ID to edit Price of food.
Enter 0 to go back to Stall menu
Enter now…. 0
List of stalls
1: ChockoMania(ID: 131).
2: Stacy’s Burger Shop(ID: 140).
3: Chicken King(ID: 300).
0: Main menu.
Enter now… 5
Wrong entry! Try again!
List of stalls
1: ChockoMania(ID: 131).
2: Stacy’s Burger
Shop(ID: 140).
3: Chicken King(ID: 300).
0: Main menu.
Enter now… 0
Main Menu
1: View stalls.
0: Exit.
Enter now… 0
Thank you! Have a great day!
BUILD SUCCESSFUL (total time: 56 seconds)