Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PIZAA Creator(ITSE1430 Version 1.1 In this lab you will create a console applica

ID: 3744887 • Letter: P

Question

PIZAA Creator(ITSE1430

Version 1.1

In this lab you will create a console application to order a pizza. The application will provide the user options to order a pizza and display the running total for the order.

Skills Needed

C#

Control flow statements

Functions and parameters

Types

Variables

Console read/write

Story 1 - Create the Project

Create a new console project to hold your code.

Open Visual Studio. Create a new project.

Select the Console App (.NET Framework) project template.

Ensure the .NET Framework 4.6.1 option is set.

Set the project name to PizzaCreator.

Ensure the location is under your Labs folder in your local Git repository.

Create the project. Compile and run the application to ensure everything is working.

Commit the project to GitHub to make sure the commit process is working.

Acceptance Criteria The application compiles cleanly without warnings or errors.

The application runs.

Story 2 - Display the Main Menu

Console applications typically have a menu to allow the user to interact with the system.

The application will allow the following options.

The options will be discussed later.

New Order

Modify Order

Display Order Quit

The cart price should be shown (with a label) each time the menu is. The cart should show the current price based upon the order.

Acceptance Criteria Display the main menu to the user.

Allow the user to select one of the valid options and then perform the requested action.

Continue to display the main menu until the user elects to quit.

If the user selects an option that is not available then display an error and continue.

The cart price is correctly shown (with currency symbol and 2 digits of precision) each time.

Note: You may use either letters or digits to provide access to your menu. If you use letters then ensure they are case insensitive.

Story 3 - Quit

Allows the user to exit the program.

Acceptance Criteria The application terminates when selected.

Story 4 - New Order

Allows the user to create a new order. If an order is already created then the user is first prompted to overwrite the existing order.

The order process walks the user through the process of creating a pizza. The following choices are available Size (one is required).

Small ($5)

Medium ($6.25)

Large ($8.75)

Meats (zero or more). Each option is $0.75 extra. The user can select or unselect the options until done.

Bacon

Ham

Pepperoni

Sausage

Vegetables (zero or more). Each option is $0.50 extra. The user can select or unselect the options until done.

Black olives

Mushrooms

Onions

Peppers

Sauce (one is required).

Traditional ($0)

Garlic ($1)

Oregano ($1)

Cheese (one is required).

Regular ($0)

Extra ($1.25)

Delivery (one is required).

Take Out ($0)

Delivery ($2.50)

After the user has entered their order information then the application will display the order information and return to the main menu.

Acceptance Criteria If no order already exists then the user starts creating a new order.

If an order exists then the user is prompted to start over.

If the user chooses yes then a new order is created. If the user chooses no then nothing happens.

User is required to select a size.

User may select zero or more meats.

User can unselect a selected meat option.

User may select zero or more vegetables.

User can unselect a selected vegetable option.

User can select a type of sauce.

User can select a type of cheese.

User can select a delivery type.

After order entry user is shown the order information.

If the user enters any invalid options then they receive an error message.

Prices are shwon in the correct currency format.

Story 5 - Display Order

Shows the order information to the user. The order information includes the order options, price for each one and the total price. Prices are shown in correct currency format.

For example.

Medium Pizza $6.25

Take Out

Meats Bacon $0.75

Ham $0.75

Vegetables

Onions $0.50

Sauce

Traditional -----------------------

Total $8.25

Acceptance Criteria All order information is shown and correct.

Order total is correct.

Prices are shwon in the correct currency format.

Story 6 - Modify Order

Allows the user to modify an existing order. If there is no existing order then an error is displayed.

The user is sent through the order process again. Any existing selections are left intact. Currently selected options are marked as selected to indicate to the user their previous choice. After the order is modified the order is displayed again.

Acceptance Criteria

If there is no existing order then display an error and return to main menu.

If there is an order then send the user back through the order process again. Each existing selection is shown and user can change the selection.

After order is finished the order is displayed as before.

Hints

Variables

USE nouns for variable names.

USE singular or plural when representing singular or multiple values, respectively.

USE the most appropriate type for each variable.

bool stores true or false values. Do not use integrals for this.

decimal stores monetary values.

double stores floating point values.

int stores integral values.

string stores textual values.

For now make any variables that are needed across function calls "global" variables. 1. Define the variable inside the Program class but outside all functions. 2. Prefix the variable declaration with private static. csharp private static decimal price;

To detect an "existing" order either use a variable that starts out initialized to an invalid state (e.g. size of 0) or use a boolean flag. Be sure that the "existing" indicator is updated properly as the application executes.

Console

Console.WriteLine can be used to write a line of text with a newline.

Console.ReadLine can be used to read an entire line input.

Console.ReadKey can be used to read a single key and, optional, not display it to the user. When using this method note that you have to use the Key property of the return value to get the actual key pressed.

Output can be colored for emphasis using the Console.ForegroundColor and Console.BackgroundColor values. If changing the color then be sure to reset the colors using Console.ResetColor

Explanation / Answer

Solution:

console application to order a pizza:

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PizzaMiniProject {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
MaximizeBox = false;
}

private void btnAdd_Click(object sender, EventArgs e) {
bool error = false;
if (lbPizzaSelection.SelectedItem != null) {
if (txtQuantity.Text != "") {
lbQuantity.Items.Add(txtQuantity.Text);
int cost = 0;
if (lbPizzaSelection.SelectedItem == "Neapolitan") {
cost = Convert.ToInt32(txtQuantity.Text) * 50;
lbAmount.Items.Add(cost);
}
if (lbPizzaSelection.SelectedItem == "Margherita") {
cost = Convert.ToInt32(txtQuantity.Text) * 60;
lbAmount.Items.Add(cost);
}
if (lbPizzaSelection.SelectedItem == "Pepperoni") {
cost = Convert.ToInt32(txtQuantity.Text) * 80;
lbAmount.Items.Add(cost);
}
if (lbPizzaSelection.SelectedItem == "Lazio") {
cost = Convert.ToInt32(txtQuantity.Text) * 70;
lbAmount.Items.Add(cost);
}
if (lbPizzaSelection.SelectedItem == "Zucchini") {
cost = Convert.ToInt32(txtQuantity.Text) * 90;
lbAmount.Items.Add(cost);
}
txtQuantity.Focus();
txtQuantity.Clear();
} else {
error = true;
MessageBox.Show("Please enter a valid Quantity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
lblAmount.Focus();
}
if (error == false) {
lbOrdered.Items.Add(lbPizzaSelection.SelectedItem);
lbPizzaSelection.Items.Remove(lbPizzaSelection.SelectedItem);
}
} else {
MessageBox.Show("No Pizza Selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void txtQuantity_KeyPress(object sender, KeyPressEventArgs e) {
char ch = e.KeyChar;
if (!Char.IsDigit(ch) && ch != 8) //method makes it so all digits[numbers] can be clicked expect the backwards which is 8.
{
e.Handled = true;
MessageBox.Show("Quantity must be a number!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btnReset_Click(object sender, EventArgs e) {
if (checkDelivery.Checked) {
checkDelivery.Checked = false;
}
lbOrdered.Items.Clear();
lbAmount.Items.Clear();
lbQuantity.Items.Clear();
lblAmount.Text = "";
lblOrder.Text = "";
MessageBox.Show("Form Reset.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void btnOrder_Click(object sender, EventArgs e) {
if (lbOrdered.Items.Count > 0) {
int sum = 0;
for (int i = 0; i < lbAmount.Items.Count; i++) {//using a dummy variable i to store
sum += Convert.ToInt32(lbAmount.Items[i].ToString());//convert to int or double in order to be mathimtical
}//add to the sum instead of keeps changing in order to get total value.
lblAmount.Text = Convert.ToString(sum);//once done re-convert to string t be used.
double[] currencies = { 1, 3.67, 5.12 };
int currency = 0;
if (currencyUAE.Checked) {
currency = 0;
}
if (currencyUS.Checked) {
currency = 1;
}
if (currencyEuro.Checked) {
currency = 2;
}
double price = int.Parse(lblAmount.Text) / currencies[currency];
lblAmount.Text = string.Format("{0:#.##}", price);
if (checkDelivery.Checked) {
double totalPrice = double.Parse(lblAmount.Text) + (double.Parse(lblAmount.Text) * 0.05);
lblOrder.Text = string.Format("{0:#.##}", totalPrice);
MessageBox.Show("Have a nice meal! - No Express Delivery!");
} else {
double totalPrice = double.Parse(lblAmount.Text);
lblOrder.Text = string.Format("{0:#.##}", totalPrice);
MessageBox.Show("Have a nice meal!");
}
} else {
MessageBox.Show("Place an order first!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}