Print Friendly and PDF
(Restaurant Bill Calculator) A restaurant wants an app that calculates a table’s bill. The app should display all the menu items from in four Combo Boxes. Each Combo Boxes should contain a category of food offered by the restaurant (Beverage, Appetizer, Main Course and Dessert). The user can choose from one of these Combo Boxes to add an item to a table’s bill. As each item is selected in the Combo Boxes, add the price of that item to the bill. The user can click the Clear Bill Button to restore the Subtotal: Tax: and Total: fields to $0.00.
(Restaurant Bill Calculator) A restaurant wants an app that calculates a table’s bill. The app should display all the menu items from in four Combo Boxes. Each Combo Boxes should contain a category of food offered by the restaurant (Beverage, Appetizer, Main Course and Dessert).
The user can choose from one of these Combo Boxes to add an item to a table’s bill. As each item is selected in the Combo Boxes, add the price of that item to the bill. The user can click the Clear Bill Button to restore the Subtotal: Tax: and Total: fields to $0.00.


Restaurant Bill Calculator

Solution

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 RestaurantBillCalc
{
    public partial class Form1 : Form
    {
        double bill = 0.00;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //bill = 0.0;
            billLabel.Text = Convert.ToString(bill);
        }

        private void checkBoxSoda_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxSoda.Checked == true)
            {
                bill += 1.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelSoda.ForeColor = Color.White;
                labelSoda.BackColor = Color.Red;
            }
            if (checkBoxSoda.Checked == false)
            {
                bill -= 1.95;
                billLabel.Text = Convert.ToString(Math.Round(bill,2));
                labelSoda.BackColor = Color.Gainsboro;
                labelSoda.ForeColor = Color.Black;
            }
        }

        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
           
        }

        private void checkBoxTea_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxTea.Checked == true)
            {
                bill += 1.50;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelTea.ForeColor = Color.White;
                labelTea.BackColor = Color.Red;
            }
            if (checkBoxTea.Checked == false)
            {
                bill -= 1.50;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelTea.BackColor = Color.Gainsboro;
                labelTea.ForeColor = Color.Black;
            }
        }

        private void checkBoxCoffee_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxCoffee.Checked == true)
            {
                bill += 1.25;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelCoffee.ForeColor = Color.White;
                labelCoffee.BackColor = Color.Red;
            }
            if (checkBoxCoffee.Checked == false)
            {
                bill -= 1.25;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelCoffee.BackColor = Color.Gainsboro;
                labelCoffee.ForeColor = Color.Black;
            }
        }

        private void checkBoxMineralWater_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxMineralWater.Checked == true)
            {
                bill += 2.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelMineralWater.ForeColor = Color.White;
                labelMineralWater.BackColor = Color.Red;
            }
            if (checkBoxMineralWater.Checked == false)
            {
                bill -= 2.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelMineralWater.BackColor = Color.Gainsboro;
                labelMineralWater.ForeColor = Color.Black;
            }
        }

        private void checkBoxJuice_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxJuice.Checked == true)
            {
                bill += 2.50;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelJuice.ForeColor = Color.White;
                labelJuice.BackColor = Color.Red;
            }
            if (checkBoxJuice.Checked == false)
            {
                bill -= 2.50;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelJuice.BackColor = Color.Gainsboro;
                labelJuice.ForeColor = Color.Black;
            }
        }

        private void checkBoxMilk_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxMilk.Checked == true)
            {
                bill += 1.50;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelMilk.ForeColor = Color.White;
                labelMilk.BackColor = Color.Red;
            }
            if (checkBoxMilk.Checked == false)
            {
                bill -= 1.50;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelMilk.BackColor = Color.Gainsboro;
                labelMilk.ForeColor = Color.Black;
            }
        }

        private void checkBoxBuffaloWings_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxBuffaloWings.Checked == true)
            {
                bill += 5.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelBuffaloWings.ForeColor = Color.White;
                labelBuffaloWings.BackColor = Color.Green;
            }
            if (checkBoxBuffaloWings.Checked == false)
            {
                bill -= 5.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelBuffaloWings.BackColor = Color.Gainsboro;
                labelBuffaloWings.ForeColor = Color.Black;
            }
        }

        private void checkBoxBuffaloFingers_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxBuffaloFingers.Checked == true)
            {
                bill += 6.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelBuffaloFingers.ForeColor = Color.White;
                labelBuffaloFingers.BackColor = Color.Green;
            }
            if (checkBoxBuffaloFingers.Checked == false)
            {
                bill -= 6.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelBuffaloFingers.BackColor = Color.Gainsboro;
                labelBuffaloFingers.ForeColor = Color.Black;
            }
        }

        private void checkBoxPotatoSkins_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxPotatoSkins.Checked == true)
            {
                bill += 8.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelPotatoSkins.ForeColor = Color.White;
                labelPotatoSkins.BackColor = Color.Green;
            }
            if (checkBoxPotatoSkins.Checked == false)
            {
                bill -= 8.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelPotatoSkins.BackColor = Color.Gainsboro;
                labelPotatoSkins.ForeColor = Color.Black;
            }
        }

        private void checkBoxChickenAlfredo_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxChickenAlfredo.Checked == true)
            {
                bill += 13.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelChickenAlfredo.ForeColor = Color.White;
                labelChickenAlfredo.BackColor = Color.Red;
            }
            if (checkBoxChickenAlfredo.Checked == false)
            {
                bill -= 13.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelChickenAlfredo.BackColor = Color.Gainsboro;
                labelChickenAlfredo.ForeColor = Color.Black;
            }
        }

        private void checkBoxChickenPicatta_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxChickenPicatta.Checked == true)
            {
                bill += 13.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelChickenPicatta.ForeColor = Color.White;
                labelChickenPicatta.BackColor = Color.Red;
            }
            if (checkBoxChickenPicatta.Checked == false)
            {
                bill -= 13.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelChickenPicatta.BackColor = Color.Gainsboro;
                labelChickenPicatta.ForeColor = Color.Black;
            }
        }

        private void checkBoxTurkeyClub_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxTurkeyClub.Checked == true)
            {
                bill += 11.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelTurkeyClub.ForeColor = Color.White;
                labelTurkeyClub.BackColor = Color.Red;
            }
            if (checkBoxTurkeyClub.Checked == false)
            {
                bill -= 11.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelTurkeyClub.BackColor = Color.Gainsboro;
                labelTurkeyClub.ForeColor = Color.Black;
            }
        }

        private void checkBoxLobsterPie_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxLobsterPie.Checked == true)
            {
                bill += 19.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelLobsterPie.ForeColor = Color.White;
                labelLobsterPie.BackColor = Color.Red;
            }
            if (checkBoxLobsterPie.Checked == false)
            {
                bill -= 19.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelLobsterPie.BackColor = Color.Gainsboro;
                labelLobsterPie.ForeColor = Color.Black;
            }
        }

        private void checkBoxPrimeRib_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxPrimeRib.Checked == true)
            {
                bill += 20.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelPrimeRib.ForeColor = Color.White;
                labelPrimeRib.BackColor = Color.Red;
            }
            if (checkBoxPrimeRib.Checked == false)
            {
                bill -= 20.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelPrimeRib.BackColor = Color.Gainsboro;
                labelPrimeRib.ForeColor = Color.Black;
            }
        }

        private void checkBoxShrimpScampi_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxShrimpScampi.Checked == true)
            {
                bill += 18.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelShrimpScampi.ForeColor = Color.White;
                labelShrimpScampi.BackColor = Color.Red;
            }
            if (checkBoxShrimpScampi.Checked == false)
            {
                bill -= 18.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelShrimpScampi.BackColor = Color.Gainsboro;
                labelShrimpScampi.ForeColor = Color.Black;
            }
        }

        private void checkBoxTurkeyDinner_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxTurkeyDinner.Checked == true)
            {
                bill += 13.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelTurkeyDinner.ForeColor = Color.White;
                labelTurkeyDinner.BackColor = Color.Red;
            }
            if (checkBoxTurkeyDinner.Checked == false)
            {
                bill -= 13.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelTurkeyDinner.BackColor = Color.Gainsboro;
                labelTurkeyDinner.ForeColor = Color.Black;
            }
        }

        private void checkBoxStuffedChicken_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxStuffedChicken.Checked == true)
            {
                bill += 14.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelStuffedChicken.ForeColor = Color.White;
                labelStuffedChicken.BackColor = Color.Red;
            }
            if (checkBoxStuffedChicken.Checked == false)
            {
                bill -= 14.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelStuffedChicken.BackColor = Color.Gainsboro;
                labelStuffedChicken.ForeColor = Color.Black;
            }
        }

        private void checkBoxApplePie_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxApplePie.Checked == true)
            {
                bill += 5.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelApplePie.ForeColor = Color.White;
                labelApplePie.BackColor = Color.Pink;
            }
            if (checkBoxApplePie.Checked == false)
            {
                bill -= 5.95;
                billLabel.Text = Convert.ToString(Math.Round(bill, 2));
                labelApplePie.BackColor = Color.Gainsboro;
                labelApplePie.ForeColor = Color.Black;
            }
        }

        private void buttonClearOrder_Click(object sender, EventArgs e)
        {
            
        }

        private void buttonViewBill_Click(object sender, EventArgs e)
        {
            string BillNOrder;
            BillNOrder = "";
            if (checkBoxSoda.Checked == true)
                BillNOrder += "Soda\t\t\t$1.95\n";
            if (checkBoxTea.Checked == true)
                BillNOrder += "Tea\t\t\t$1.50\n";
            if (checkBoxCoffee.Checked == true)
                BillNOrder += "Coffee\t\t\t$1.25\n";
            if (checkBoxMineralWater.Checked == true)
                BillNOrder += "Mineral Water\t\t\t$2.95\n";
            if (checkBoxJuice.Checked == true)
                BillNOrder += "Juice\t\t\t$2.50\n";
            if (checkBoxMilk.Checked == true)
                BillNOrder += "Milk\t\t\t$1.50\n";
            if (checkBoxBuffaloWings.Checked == true)
                BillNOrder += "Buffalo Wings\t\t\t$5.95\n";
            if (checkBoxBuffaloFingers.Checked == true)
                BillNOrder += "Buffallo Fingers\t\t\t$6.95\n";
            if (checkBoxPotatoSkins.Checked == true)
                BillNOrder += "Potato Skins\t\t\t$8.95\n";
            if (checkBoxChickenAlfredo.Checked == true)
                BillNOrder += "Chicken Alfredo\t\t\t$13.95\n";
            if (checkBoxChickenPicatta.Checked == true)
                BillNOrder += "Chicken Picatta\t\t\t$13.95\n";
            if (checkBoxTurkeyClub.Checked == true)
                BillNOrder += "Turkey Club\t\t\t$11.95\n";
            if (checkBoxLobsterPie.Checked == true)
                BillNOrder += "Lobster Pie\t\t\t$19.95\n";
            if (checkBoxPrimeRib.Checked == true)
                BillNOrder += "Prime Rib\t\t\t$20.95\n";
            if (checkBoxShrimpScampi.Checked == true)
                BillNOrder += "Shrimp Scampi\t\t\t$18.95\n";
            if (checkBoxTurkeyDinner.Checked == true)
                BillNOrder += "Turkey Dinner\t\t\t$13.95\n";
            if (checkBoxStuffedChicken.Checked == true)
                BillNOrder += "Stuffed Chicken\t\t\t$14.95\n";
            if (checkBoxApplePie.Checked == true)
                BillNOrder += "Apple Pie\t\t\t$5.95\n";
            BillNOrder += "Total Bill\t\t\t$" + Math.Round(bill, 2);
            BillNOrder += "\n";
            MessageBox.Show(BillNOrder);
            //buttonClearOrder.PerformClick();
            checkBoxSoda.Checked = false;
            checkBoxTea.Checked = false;
            checkBoxCoffee.Checked = false;
            checkBoxMineralWater.Checked = false;
            checkBoxJuice.Checked = false;
            checkBoxMilk.Checked = false;
            checkBoxBuffaloWings.Checked = false;
            checkBoxBuffaloFingers.Checked = false;
            checkBoxPotatoSkins.Checked = false;
            checkBoxChickenAlfredo.Checked = false;
            checkBoxChickenPicatta.Checked = false;
            checkBoxTurkeyClub.Checked = false;
            checkBoxLobsterPie.Checked = false;
            checkBoxPrimeRib.Checked = false;
            checkBoxShrimpScampi.Checked = false;
            checkBoxTurkeyDinner.Checked = false;
            checkBoxStuffedChicken.Checked = false;
            checkBoxApplePie.Checked = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: