Question

How can I add this function to my C# code?:

Validate that if the user clicks the “OK” button, a “Seating Category” is selected, and at least one ticket is being purchased. If not, pop-up a dialog box asking the user to enter the needed data for the transaction. What we want to avoid is depicted in See Figure 3.

Figure 3:

K-State Athletic Depart X Seating Category O Student O Alumni O Military O Faculty or Statt O General Put You ordered o ticke

This code asks for a seating category to be selected, how many tickets to be purchased, and if a parking pass is needed. Thank you!!

Form1.cs File:

using System;

using System.Windows.Forms;

namespace Proj4

{

    public partial class Form1 : Form

    {

        // Declare constants for proces

        const int COST_STUDENT_PERCENTAGE = 50;

        const int COST_ALUMNI_PERCENTAGE = 10;

        const int COST_MILITARY_PERCENTAGE = 20;

        const int COST_FACULTY_STAFF_PERCENTAGE = 15;

        const int COST_GENERAL = 80;

        const int COST_PARKING = 25;

        public Form1()

        {

            InitializeComponent();

        }

        private void btOK_Click(object sender, EventArgs e)

        {

            double cost = COST_GENERAL, total = 0.0;

            // Determine cost based on the radio button selection

            if (rbStudent.Checked)

            {

                cost -= cost * COST_STUDENT_PERCENTAGE / 100;

            }

            else if(rbAlumni.Checked)

            {

                cost -= cost * COST_ALUMNI_PERCENTAGE / 100;

            }

            else if(rbMilitary.Checked)

            {

                cost = cost * COST_MILITARY_PERCENTAGE / 100;

            }

            else if(rbFaculty.Checked)

            {

                cost -= cost * COST_FACULTY_STAFF_PERCENTAGE / 100;

            }

            else if(rbGeneral.Checked)

            {

                cost = COST_GENERAL;

            }

            else

            {

                MessageBox.Show("Select seating category");

                return;

            }

            // calculating the total cost

            int numTicktes = (int)nudTickets.Value;

            total = cost * numTicktes;

            //if parking was added

            if (cbParking.Checked)

            {

                total += COST_PARKING;

                MessageBox.Show("You ordered " + numTicktes + " tickets(s) with parking for a total cost of " + total.ToString("C"));

            }

            else

            {

                MessageBox.Show("You ordered " + numTicktes + " tickets(s) for a total cost of " + total.ToString("C"));

            }

        }

    }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Application name :Proj4

Language used :C#

IDE used :Visual Studio 2019

User interface :Form1.cs[Design]

K-State Athletic Department X Seating Category Student Alumni Military O Faculty or Staff General Public Number of Tickets Pa

******************************************

Form1.cs :

//namespace
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;
//application namespace
namespace Proj4
{
public partial class Form1 : Form
{
// Declare constants for proces
const int COST_STUDENT_PERCENTAGE = 50;
const int COST_ALUMNI_PERCENTAGE = 10;
const int COST_MILITARY_PERCENTAGE = 20;
const int COST_FACULTY_STAFF_PERCENTAGE = 15;
const int COST_GENERAL = 80;
const int COST_PARKING = 25;
public Form1()
{
InitializeComponent();
}

//This is click event for OK Button
private void btOK_Click(object sender, EventArgs e)
{
//checking if radio buttons that is seating capacity is selected
//and number of tickets are greater than 0
if ((rbStudent.Checked || rbAlumni.Checked || rbFaculty.Checked || rbGeneral.Checked || rbMilitary.Checked) && (int)(nudTickets.Value) > 0)
{
double cost = COST_GENERAL, total = 0.0;
// Determine cost based on the radio button selection
if (rbStudent.Checked)
{
cost -= cost * COST_STUDENT_PERCENTAGE / 100;
}
else if (rbAlumni.Checked)
{
cost -= cost * COST_ALUMNI_PERCENTAGE / 100;
}
else if (rbMilitary.Checked)
{
cost = cost * COST_MILITARY_PERCENTAGE / 100;
}
else if (rbFaculty.Checked)
{
cost -= cost * COST_FACULTY_STAFF_PERCENTAGE / 100;
}
else if (rbGeneral.Checked)
{
cost = COST_GENERAL;
}
else
{
MessageBox.Show("Select seating category");
return;
}
// calculating the total cost
int numTicktes = (int)nudTickets.Value;
total = cost * numTicktes;
//if parking was added
if (cbParking.Checked)
{
total += COST_PARKING;
MessageBox.Show("You ordered " + numTicktes + " tickets(s) with parking for a total cost of " + total.ToString("C"));
}
else
{
MessageBox.Show("You ordered " + numTicktes + " tickets(s) for a total cost of " + total.ToString("C"));
}
}
else
{
//When seating capacity is not selected or number of tickets are less than 0
MessageBox.Show("Select seating capacity or number of Ticket greater than 0");
}
}
}
}
===================================

Screen when either parking tickets are less than 0 or seating capacity is not selected :

K-State Athletic Department Seating Category Student Alumni Military Faculty or Staff General Public Number of Tickets Parkin

Screen showing cost :

K-State Athletic Department X Seating Category Student Alumni Military X Faculty or Staff General Public You ordered 2 ticket

Add a comment
Know the answer?
Add Answer to:
How can I add this function to my C# code?: Validate that if the user clicks...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi everyone, For my Assignment I have to use C# in order to create a validation...

    Hi everyone, For my Assignment I have to use C# in order to create a validation form and include the following things to register and validate: Email Address, Username, Password, Retype Password, and a Submit Button. I have figured out some of the code for the Email Address validation: 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 Validation4 {     public partial class Form1 : Form     {        ...

  • Here is my skeleton code to this C# assignement I need to add a few things,...

    Here is my skeleton code to this C# assignement I need to add a few things, Change the the switch to If and Else-If statements (and test it is still working here) Add a third "Submit" button called SubmitButton In your If and Else-If add a condition if city is Honolulu and SubmitButton is checked. Display "Honolulu is the best place to be this time of year! I wish I was there!". Add comments, including header. HELP PLEASE ASAP public...

  • C#: I am working on this application and keep running into this error. Please help me fix it. Err...

    C#: I am working on this application and keep running into this error. Please help me fix it. Error: Design: 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 SinghAjayProgram08 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } double totalInserted = 0; double totalWon = 0; private void spinButton_Click(object sender, EventArgs e) { Random rand = new Random(); int index = rand.Next(fruitsImageList.Images.Count); firstPictureBox.Image =...

  • Can you help us!! Thank you! C++ Write a program that can be used by a...

    Can you help us!! Thank you! C++ Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...

  • C# Windows Form Application (CALCULATOR): (This is the instruction below): Windows Calculator that will going to...

    C# Windows Form Application (CALCULATOR): (This is the instruction below): Windows Calculator that will going to create a Windows Form Application that will mimics a calculator. This is the screenshot how it shouldl look like. Calculator It should have a textbox and the following buttons: + Addition - Subtraction * Multiplication / Division = Equals (Will perform the final calculation) C Clear (Will clear the text box) There will be no maximize or minimize buttons. The rules are these: 2...

  • C# Temperature Converter Application: I have most of the application complete I just need only help...

    C# Temperature Converter Application: I have most of the application complete I just need only help with error messages. My instructor wants me to show four error messages inside an error message label (not a message box) and all of the error messages should appear inside error message label. The four error messages should appear when: 1: User enters data inside both Celsius and fahrenheit text boxes: “You should enter data in only one textbox. Press Clear to start over.”...

  • how to add methods into thjs code using C# on visual studio? -validatetextbox should return a true false depending if input is valid -resetinput should clear all input and restart radiobuttons...

    how to add methods into thjs code using C# on visual studio? -validatetextbox should return a true false depending if input is valid -resetinput should clear all input and restart radiobuttons to the defult positions -displaymessge must display messge box to the user displaying such as “5+8=12” calculator.cs x Prearam S Miscellaneous Files ator.Designer.c s Calculato 1 曰using Systemi 2 using System.Collections.Generic; using System.ComponentModel; 4 using System.Data; s using System.Drawing; 6 using System.Linq 7using System.Text; 8 using System.Threading.Tasks; 9 using...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • How do I set up my read function? here's my code so far: int read_sudoku_board(const char file_name[], int board[9][9]) { FILE * fp = fopen("sudoku.txt", "r"); int a,i,j,c;...

    How do I set up my read function? here's my code so far: int read_sudoku_board(const char file_name[], int board[9][9]) { FILE * fp = fopen("sudoku.txt", "r"); int a,i,j,c; int count = 0; for(i = 0; i < a; i++){ for(j = 0;j < 9;j++){ c = fgetc(fp); if(c == '-'){ board[i][j] = 0; } else if(c >= 1 && c <= 9) printf(" %d"); else return -2; } count++; } if(count != a-1) return -1; else return 0; }12 Read...

  • I need help with my coding for C++! The goal of this is to calculate the...

    I need help with my coding for C++! The goal of this is to calculate the total cost of a product by combining the products price and the amount of tax, then display it to the user. The numbers we have to test out is 100 for the price and 8.25 for the percentage. When I test is out, the formula works but it isn't rounding the 108.25 to 108.3, which is the total price we are supposed to display...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT