Question
Project Outcomes: 1.To develop skills in using the Java selection constructs (if, if else and switch). 2.Use the Java iteration constructs (while, do, for). 3.Use
Project Outcomes:
1.To develop skills in using the Java selection constructs (if, if else and switch).
2.Use the Java iteration constructs (while, do, for).
3.Use Boolean variables and expressions to control iterations.
4.Switch operated text menu.
5.Proper Design techniques including reading UML Class Diagrams
Preparatory Readings:
Java textbook, chapter 1 - 7.
Switch operated text menu: http://www.javaforstudents.co.uk/Code_snippets/Switch-operated_text_menu
UML Information:
The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class diagram, which are used to depict the attributes and behaviors of a class. A basic class diagram (as shown in the figure below) has three components. The first is the class name. The second component includes the class's attributes or fields. Each attribute is followed by a colon (:) and its data type. The third component includes the class's behaviors or methods. If the method takes parameters, their types are included in parentheses. Each behavior is also followed by a colon (:) and its return type. If the return value of a method is void, the return type can be omitted. For more information on the UML, refer to http://www.uml.org/.
Project Description:
1)Develop a class that simulates a Pizza ordering system. In this program, customer will be able to check prices, order pizza, review total price, and cancel order. The UML class diagram of PizzaOrdering class is shown below.
PizzaOrdering |
LARGE_PIZZA_PRICE:double MEDIUM_PIZZA_PRICE:double SMALL_PIZZA_PRICE:double totalExpense:double |
PizzaOrdering () mainMenu():void listPrices():void placeOrder():void displayTotal():void cancelOrder():void |
2)User will enter the main menu first and choose from five options:
1.List prices;
2.Place order;
3.Display total amount to pay;
4.Cancel the current order;
5.Exit program.
User will be asked Please in put the choice (1-5): and input a number and hit enter to choose the option.
3)List price option will display the prices of three difference pizza size and return to main menu immediately:
Large pizza: $16.99
Medium pizza: $14.99
Small pizza: $12.99
4)The prices should be pre-stored in three constants (static final variable, think about why.) LARGE_PIZZA_PRICE, MEDIUM_PIZZA_PRICE and SMALL_PIZZA_PRICE rather than hard coded in the println statements.
5)Place order option will
1.Ask user to input the size of pizza to order first and take user input of integer between 1 and 3:
Please choose the size of pizza (1. Large; 2. Medium; 3. Small):
2.Then ask user to input the amount of the pizzas to order and allow the maximum of 10 pizza to be ordered in one round:
Please input the amount of pizza you want to order (1-10):
3.The subtotal is then calculated as unit price times amount and is added to the total expense. It is not necessary to store anything. Just update the total expense variable value;
4.Finally, ask user if they want to continue ordering more and check the user input for y or n:
Do you want to order more? (y/n)
5.If y (or Y) is found, go back to step 1. Otherwise, exit to mainMenu.
6)Display total option will display the total expense of the order and immediate exit to main menu:
Your current total is $32.97.
7)Cancel order option will reset the total expense to 0 and display the message and then exit to main menu:
Your order is canceled and your total expense is 0 now.
8)The exit option will exit the program.
PizzaOrdering class:
1)Variables and constants
LARGE_PIZZA_PRICE, MEDIUM_PIZZA_PRICE and SMALL_PIZZA_PRICE stores the unit prices of three sizes of pizza
totalExpense stores the total amount of money due for current order
A totalExpense variable is defined to store the current total
All variables are initialized to its initial values
2)Constructor and Methods
Default Constructor is required. You can initialize any non-constant fields like totalExpense here if you have not done so when declaring it;
Method mainMenu is the entry point of this class, which displays the main menu and use a loop to interact with user. Once user choice is read in. The corresponding methods will be called. You may consider a switch statement to delegate the task according to the user input. If user choose to exit, the loop will end and the program will quit;
Method listPrices will display the unit prices of three different sizes of pizza and immediately return to main menu;
Method placeOrder handle the pizza ordering and update the total expense variable;
Method displayTotal will display the current total expense;
Method cancelOrder will display a message and reset the total expense.
PizzaOrderingRunner class
1)This program have the main method as the entry point. In the main method, it will create a PizzaOrdering object and call its mainMenu method to start the program.
2)Must have this class. Do not combine the runner responsibility to the mail PizzaOrdering class!
Sample Output: user inputs are highlighted in red
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 0
Please in put the choice (1-5): -1
Please in put the choice (1-5): 16
Please in put the choice (1-5): 1
Large pizza: $16.99
Medium pizza: $14.99
Small pizza: $12.99
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 3
Your current total is $0.00
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 2
Please choose the size of pizza (1. Large; 2. Medium; 3. Small): 0
Please choose the size of pizza (1. Large; 2. Medium; 3. Small): 45
Please choose the size of pizza (1. Large; 2. Medium; 3. Small): 3
Please input the amount of pizza you want to order (1-10): -1
Please input the amount of pizza you want to order (1-10): 19
Please input the amount of pizza you want to order (1-10): 6
Do you want to order more? (y/n) y
Please choose the size of pizza (1. Large; 2. Medium; 3. Small): 1
Please input the amount of pizza you want to order (1-10): 1
Do you want to order more? (y/n) n
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 3
Your current total is $94.93
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 4
Your order is canceled and your total expense is 0 now.
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 3
Your current total is $0.00
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 5
Thank you for using!
Implementation Notes:
1)The implementation of the text menu:
a.The loop will continue to run until user choose exit option
b.The program should be able to handle out of range input (no try catch for type mismatching input) and ask user to enter again.
c.A boolean variable may be used as the flag to decide if the loop should end.
2)All numeric variables are double type. Format it to two decimal place when printing as currency. Either printf or formatter will be good choice.
3)All method should handle its own responsibility, please do not implement empty methods and put all logics in the main method.
4)Javadoc is required for all classes and methods. Other comments are optional if you feel clarification is necessary. Class javadoc should be right above the class definition and below package and import clauses. Method javadoc should be right above the method definition.
Submission Requirements:
Your project should follow the instructions below. Any submissions that do not follow the stated requirements will not be graded.
1.Follow the submission requirements.
2.You should have two files for this assignment:
a.PizzaOrdering.java - The PizzaOrdering class
b.PizzaOrderingRunner.java the runner class
3.Put both .java file in a zip file and rename it to the correct form
4.Remember to compile and run your program one last time before you submit it. If your program will not compile, the graders will not be responsible for trying to test it.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started