Question

In: Computer Science

USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...

USING VISUAL STUDIO 2017, LANGUAGE VISUAL C#

I have struggled on this program for quite some time and still can't quite figure it out.

I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number of tickets, and total price. The ticketbase = 50, weekend upcharge = 30, for Imax & Upac theaters = 35 and for Capital and Premier theaters = 25. There are 4 buttons: Process customer, Display daily report, clear all, and exit. For the process customer button, it is clicked after customer has inputted their info in textbox1 and 2 and selected from listbox 1 and 2. it is supposed to compute the cost of tickets and enter that data into an array, not more than 5 customers can be processed without clearing all with the clear all button. Once process customer button is pressed it displays a message box displaying "customer processed", and all selected inputs should be cleared after pressing OK. In the display daily report button it is supposed to take array elements using a loop, one at a time and add them to the listbox3. There are supposed to be 2-3 arrays for the input one for name of customer, another for number of tickets, and another for the cost. And for the output it is supposed to be stored in internal arrays. I am not sure of how to set this up.

Solutions

Expert Solution

Short Summary:

  • Implemented a windows application using C#.
  • Provided designer.cs file for your reference

Source Code:

Form1.cs File:

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 BookingApp

{

    public partial class Form1 : Form

    {

        // Arrays to hold the input values

        string[] name;

        int[] numTickets;

        //string[] days;

        //string[] theaters;

        int[] costs;

        const int MAX_CUSTOMERS = 5;

        int currentCapacity;

        // Ticket costs

        const int TICKET_BASE = 50;

        const int WEEKEND_UPCHARGE = 30;

        const int IMAX_COST = 35;

        const int UPAC_COST = 35;

        const int CAPTIAL_COST = 25;

        const int PREMIER_COST = 25;

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            // Initialize the array

            name = new string[MAX_CUSTOMERS];

            numTickets = new int[MAX_CUSTOMERS];

            //days = new string[MAX_CUSTOMERS];

            //theaters = new string[MAX_CUSTOMERS];

            costs = new int[MAX_CUSTOMERS];

            currentCapacity = 0;

        }

        /// <summary>

        /// Calculates total costs for the given input

        /// </summary>

        private int GetCost(int numTicket, string day, string theater)

        {

            int totalcost = TICKET_BASE;

            //weekend upcharge

            if(day == "Saturday" || day == "Sunday")

            {

                totalcost += WEEKEND_UPCHARGE;

            }

            // Add theater cost

            if(theater == "Imax")

            {

                totalcost += IMAX_COST;

            }

            else if(theater == "Upac")

            {

                totalcost += UPAC_COST;

            }

            else if (theater == "Capital")

            {

                totalcost += CAPTIAL_COST;

            }

            else if (theater == "Premier")

            {

                totalcost += PREMIER_COST;

            }

            //return the total

            return totalcost;

        }

        /// <summary>

        /// Reset the input boxes

        /// </summary>

        private void ResetInputs()

        {

            txtCustName.Text = "";

            txtNumOfTickets.Text = "";

            lbDays.SelectedIndex = -1;

            lbTheater.SelectedIndex = -1;

        }

        private void btnProcess_Click(object sender, EventArgs e)

        {

            // Validate if it has enough capacity

            if(MAX_CUSTOMERS == currentCapacity)

            {

                MessageBox.Show("Reached maximum capacity, clear all before proceed to add new customer",

                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

          }

            // Validate if customer entered

            if (string.IsNullOrEmpty(txtCustName.Text.Trim()))

            {

                MessageBox.Show("Enter customer name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            // validate if number of tickcets

            int numTicket = 0;

            if (int.TryParse(txtNumOfTickets.Text.Trim(), out numTicket) == false || numTicket <= 0)

            {

                MessageBox.Show("Enter valid number of tickets", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            // Validate if day is selected

            if(lbDays.SelectedIndex == -1)

            {

                MessageBox.Show("Select a day of the week", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            // Validate if theater is selected

            if (lbTheater.SelectedIndex == -1)

            {

                MessageBox.Show("Select a theater", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            // Add input values to the array

            name[currentCapacity] = txtCustName.Text.Trim();

            numTickets[currentCapacity] = numTicket;

            //days[currentCapacity] = lbDays.SelectedItem.ToString();

            //theaters[currentCapacity] = lbTheater.SelectedItem.ToString();

            costs[currentCapacity] = GetCost(numTicket, lbDays.SelectedItem.ToString(), lbTheater.SelectedItem.ToString());

            // Increase the current index

            currentCapacity++;

            // Display the meesage

            MessageBox.Show("Customer processed", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            // clear the inputs

            ResetInputs();

            txtCustName.Focus();

        }

        private void btnDailyReport_Click(object sender, EventArgs e)

        {

            // clear any previous values

            lbResults.Items.Clear();

            lbResults.Items.Add(string.Format("{0, -10} {1, 10} {2, 10}", "Name", "NumTickets", "TotalCost"));

            for (int index = 0; index < currentCapacity; index++)

            {

                lbResults.Items.Add(string.Format("{0, -10} {1, 10} {2, 10}", name[index], numTickets[index], costs[index]));

            }

        }

        private void btnClear_Click(object sender, EventArgs e)

        {

            ResetInputs();

            lbResults.Items.Clear();

            Array.Clear(name, 0, MAX_CUSTOMERS);

            Array.Clear(numTickets, 0, MAX_CUSTOMERS);

            Array.Clear(costs, 0, MAX_CUSTOMERS);

            currentCapacity = 0;

        }

        private void btnExit_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }

    }

}

Form1.designer.cs File:

namespace BookingApp

{

    partial class Form1

    {

        /// <summary>

        /// Required designer variable.

        /// </summary>

        private System.ComponentModel.IContainer components = null;

        /// <summary>

        /// Clean up any resources being used.

        /// </summary>

        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

        protected override void Dispose(bool disposing)

        {

            if (disposing && (components != null))

            {

                components.Dispose();

            }

            base.Dispose(disposing);

        }

       #region Windows Form Designer generated code

        /// <summary>

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()

        {

            this.label1 = new System.Windows.Forms.Label();

            this.txtCustName = new System.Windows.Forms.TextBox();

            this.txtNumOfTickets = new System.Windows.Forms.TextBox();

            this.label2 = new System.Windows.Forms.Label();

            this.lbDays = new System.Windows.Forms.ListBox();

            this.label3 = new System.Windows.Forms.Label();

            this.label4 = new System.Windows.Forms.Label();

            this.lbTheater = new System.Windows.Forms.ListBox();

            this.btnProcess = new System.Windows.Forms.Button();

            this.btnDailyReport = new System.Windows.Forms.Button();

            this.btnClear = new System.Windows.Forms.Button();

            this.btnExit = new System.Windows.Forms.Button();

            this.lbResults = new System.Windows.Forms.ListBox();

            this.label5 = new System.Windows.Forms.Label();

            this.SuspendLayout();

            //

            // label1

            //

            this.label1.AutoSize = true;

            this.label1.Location = new System.Drawing.Point(89, 57);

            this.label1.Name = "label1";

            this.label1.Size = new System.Drawing.Size(132, 20);

            this.label1.TabIndex = 0;

            this.label1.Text = "Customer Name: ";

            //

            // txtCustName

            //

            this.txtCustName.Location = new System.Drawing.Point(265, 54);

            this.txtCustName.Name = "txtCustName";

            this.txtCustName.Size = new System.Drawing.Size(257, 26);

            this.txtCustName.TabIndex = 1;

            //

            // txtNumOfTickets

            //

            this.txtNumOfTickets.Location = new System.Drawing.Point(265, 115);

            this.txtNumOfTickets.Name = "txtNumOfTickets";

            this.txtNumOfTickets.Size = new System.Drawing.Size(257, 26);

            this.txtNumOfTickets.TabIndex = 3;

            //

            // label2

            //

            this.label2.AutoSize = true;

            this.label2.Location = new System.Drawing.Point(80, 118);

            this.label2.Name = "label2";

            this.label2.Size = new System.Drawing.Size(141, 20);

            this.label2.TabIndex = 2;

            this.label2.Text = "Number of Tickets:";

            //

            // lbDays

            //

            this.lbDays.FormattingEnabled = true;

            this.lbDays.ItemHeight = 20;

            this.lbDays.Items.AddRange(new object[] {

            "Sunday",

            "Monday",

            "Tuesday",

            "Wednesday",

            "Thursday",

            "Friday",

            "Saturday"});

            this.lbDays.Location = new System.Drawing.Point(265, 177);

            this.lbDays.Name = "lbDays";

            this.lbDays.Size = new System.Drawing.Size(160, 164);

            this.lbDays.TabIndex = 4;

            //

            // label3

          //

            this.label3.AutoSize = true;

            this.label3.Location = new System.Drawing.Point(117, 177);

            this.label3.Name = "label3";

            this.label3.Size = new System.Drawing.Size(104, 20);

            this.label3.TabIndex = 5;

            this.label3.Text = "Day of Week:";

            //

            // label4

            //

            this.label4.AutoSize = true;

            this.label4.Location = new System.Drawing.Point(91, 376);

            this.label4.Name = "label4";

            this.label4.Size = new System.Drawing.Size(130, 20);

            this.label4.TabIndex = 6;

            this.label4.Text = "Select a Theater:";

            //

            // lbTheater

            //

            this.lbTheater.FormattingEnabled = true;

            this.lbTheater.ItemHeight = 20;

            this.lbTheater.Items.AddRange(new object[] {

            "Imax",

            "Upac",

            "Capital",

            "Premier"});

            this.lbTheater.Location = new System.Drawing.Point(265, 376);

            this.lbTheater.Name = "lbTheater";

            this.lbTheater.Size = new System.Drawing.Size(160, 144);

            this.lbTheater.TabIndex = 7;

            //

            // btnProcess

            //

            this.btnProcess.Location = new System.Drawing.Point(65, 564);

            this.btnProcess.Name = "btnProcess";

            this.btnProcess.Size = new System.Drawing.Size(182, 38);

            this.btnProcess.TabIndex = 8;

            this.btnProcess.Text = "Process Customer";

            this.btnProcess.UseVisualStyleBackColor = true;

            this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click);

            //

            // btnDailyReport

            //

            this.btnDailyReport.Location = new System.Drawing.Point(340, 564);

            this.btnDailyReport.Name = "btnDailyReport";

            this.btnDailyReport.Size = new System.Drawing.Size(182, 38);

            this.btnDailyReport.TabIndex = 9;

            this.btnDailyReport.Text = "Display Daily Report";

            this.btnDailyReport.UseVisualStyleBackColor = true;

            this.btnDailyReport.Click += new System.EventHandler(this.btnDailyReport_Click);

            //

            // btnClear

            //

            this.btnClear.Location = new System.Drawing.Point(65, 649);

            this.btnClear.Name = "btnClear";

            this.btnClear.Size = new System.Drawing.Size(182, 38);

            this.btnClear.TabIndex = 10;

            this.btnClear.Text = "Clear All";

            this.btnClear.UseVisualStyleBackColor = true;

            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);

            //

            // btnExit

            //

            this.btnExit.Location = new System.Drawing.Point(340, 649);

            this.btnExit.Name = "btnExit";

            this.btnExit.Size = new System.Drawing.Size(182, 38);

            this.btnExit.TabIndex = 11;

            this.btnExit.Text = "Exit";

            this.btnExit.UseVisualStyleBackColor = true;

            this.btnExit.Click += new System.EventHandler(this.btnExit_Click);

            //

            // lbResults

            //

            this.lbResults.Enabled = false;

            this.lbResults.FormattingEnabled = true;

            this.lbResults.ItemHeight = 20;

            this.lbResults.Location = new System.Drawing.Point(265, 778);

            this.lbResults.Name = "lbResults";

            this.lbResults.Size = new System.Drawing.Size(325, 204);

            this.lbResults.TabIndex = 12;

            //

            // label5

            //

            this.label5.AutoSize = true;

            this.label5.Location = new System.Drawing.Point(93, 778);

            this.label5.Name = "label5";

            this.label5.Size = new System.Drawing.Size(114, 20);

            this.label5.TabIndex = 13;

            this.label5.Text = "Display Result:";

            //

            // Form1

            //

            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientSize = new System.Drawing.Size(649, 1028);

            this.Controls.Add(this.label5);

            this.Controls.Add(this.lbResults);

            this.Controls.Add(this.btnExit);

            this.Controls.Add(this.btnClear);

            this.Controls.Add(this.btnDailyReport);

            t


Related Solutions

Subject- ( App Development for Web) ( language C#, software -visual studio) I have created a...
Subject- ( App Development for Web) ( language C#, software -visual studio) I have created a 'Calculator' named program in visual studio. This is the main console program(Program.cs) shown below. Then i have created a "CaculatorLibrary" named project by adding the project from FILE--->ADD--->NEW PROJECT. Then i selected library and selected classLibrary(.NETcore). The programs for both are given below. There are no errors in the program. Now the requirement is to build unit test project within this project that will...
Write a C-based language program in visual studio that uses an array of structs that stores...
Write a C-based language program in visual studio that uses an array of structs that stores student information including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,”). Write the same program in the same language without using structs.
answer the following using C# Design and program a Visual Studio Console project in C# that...
answer the following using C# Design and program a Visual Studio Console project in C# that allows your user to enter a number. The program will examine the number to see if it is prime. If it is prime, it will print the next higher prime and the next lower primes to the console. If the number entered by the user is not prime, display a message to that effect. All code should be written by you. Do not copy/paste...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount....
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date"...
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date" option, I get to enter list of dates like 02/08/1990, 06/14/1890 in (mm/dd/YYYY) format. How can I sort these dates in ascending order?. Can you provide me some code. Thank you
In Assembly Language (Visual Studio 2017), create a procedure that generates a random string of Length...
In Assembly Language (Visual Studio 2017), create a procedure that generates a random string of Length L, containing all capital letters. When calling the procedure, pass the value of L in EAX, and pass a pointer to an array of byte that will hold the random string. Write a test program that calls your procedure 20 times and displays the strings in the console window. In your program, the random string size shall be preset as a constant. Please include...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT