Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# Windows form application. I'm stuck on how to mark the check boxes 1 to 5 in first and 6 to 10 in economy, When

C# Windows form application.

I'm stuck on how to mark the check boxes 1 to 5 in first and 6 to 10 in economy, When I select one of the radio buttons and hit reserve.

For example I select economy radio button, click reserve, the checkbox 1 should be greyed and disabled so it can't be automatically selected, and so on until all selections are made, and it returns a message airline full. I think my code may need to reworked abit, it didn't run well last time for me.

image text in transcribed You will need to have two radio buttons to select First Class or Economy. On load, make radio button Economy selected (default). You will use only one button Reserve that should be disabled after all seats are reserved. What is new here is how seats are represented: you have to use checkboxes. At start, no checkboxes are selected. After each click on the Reserve button a correstponding cheackbox should be selected and disabled. You must have these methods implemented in a class Reserver that is separate from your Form: public bool IsFirstClassAvailable() public bool IsEconomyClassAvailable() public int ReserveFirstClassAnySeat() public int ReserveEconomyClassAnySeat() public bool[] GetAllSeats() public bool[] GetFirstClassSeats() public bool[] GetEconomyClassSeats() public void DisplayAllSeats() //this may be in your Form

amespace AirlinesReservation { partial class frmReservations { ///

/// Required designer variable. /// private System.ComponentModel.IContainer components = null;

///

/// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }

#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.lblAirlineReserve = new System.Windows.Forms.Label(); this.rdbnFirstClass = new System.Windows.Forms.RadioButton(); this.rdbnEconomyClass = new System.Windows.Forms.RadioButton(); this.btnReservations = new System.Windows.Forms.Button(); this.lblMessage = new System.Windows.Forms.Label(); this.lblAirplaneFull = new System.Windows.Forms.Label(); this.btnExit = new System.Windows.Forms.Button(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.checkBox3 = new System.Windows.Forms.CheckBox(); this.checkBox4 = new System.Windows.Forms.CheckBox(); this.checkBox5 = new System.Windows.Forms.CheckBox(); this.checkBox6 = new System.Windows.Forms.CheckBox(); this.checkBox7 = new System.Windows.Forms.CheckBox(); this.checkBox8 = new System.Windows.Forms.CheckBox(); this.checkBox9 = new System.Windows.Forms.CheckBox(); this.checkBox10 = new System.Windows.Forms.CheckBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lblAirlineReserve // this.lblAirlineReserve.Location = new System.Drawing.Point(12, 22); this.lblAirlineReserve.Name = "lblAirlineReserve"; this.lblAirlineReserve.Size = new System.Drawing.Size(100, 23); this.lblAirlineReserve.TabIndex = 0; this.lblAirlineReserve.Text = "Airline Reservation"; // // rdbnFirstClass // this.rdbnFirstClass.AutoSize = true; this.rdbnFirstClass.Location = new System.Drawing.Point(15, 48); this.rdbnFirstClass.Name = "rdbnFirstClass"; this.rdbnFirstClass.Size = new System.Drawing.Size(72, 17); this.rdbnFirstClass.TabIndex = 1; this.rdbnFirstClass.TabStop = true; this.rdbnFirstClass.Text = "First Class"; this.rdbnFirstClass.UseVisualStyleBackColor = true; this.rdbnFirstClass.CheckedChanged += new System.EventHandler(this.rdbnFirstClass_CheckedChanged); // // rdbnEconomyClass // this.rdbnEconomyClass.AutoSize = true; this.rdbnEconomyClass.Location = new System.Drawing.Point(15, 71); this.rdbnEconomyClass.Name = "rdbnEconomyClass"; this.rdbnEconomyClass.Size = new System.Drawing.Size(97, 17); this.rdbnEconomyClass.TabIndex = 2; this.rdbnEconomyClass.TabStop = true; this.rdbnEconomyClass.Text = "Economy Class"; this.rdbnEconomyClass.UseVisualStyleBackColor = true; this.rdbnEconomyClass.CheckedChanged += new System.EventHandler(this.rdbnEconomyClass_CheckedChanged); // // btnReservations // this.btnReservations.Location = new System.Drawing.Point(12, 99); this.btnReservations.Name = "btnReservations"; this.btnReservations.Size = new System.Drawing.Size(97, 23); this.btnReservations.TabIndex = 3; this.btnReservations.Text = "Reservations"; this.btnReservations.UseVisualStyleBackColor = true; this.btnReservations.Click += new System.EventHandler(this.btnReservations_Click); // // lblMessage // this.lblMessage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lblMessage.Location = new System.Drawing.Point(12, 138); this.lblMessage.Name = "lblMessage"; this.lblMessage.Size = new System.Drawing.Size(260, 43); this.lblMessage.TabIndex = 4; this.lblMessage.UseMnemonic = false; // // lblAirplaneFull // this.lblAirplaneFull.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lblAirplaneFull.Location = new System.Drawing.Point(12, 197); this.lblAirplaneFull.Name = "lblAirplaneFull"; this.lblAirplaneFull.Size = new System.Drawing.Size(260, 42); this.lblAirplaneFull.TabIndex = 5; // // btnExit // this.btnExit.Location = new System.Drawing.Point(125, 99); this.btnExit.Name = "btnExit"; this.btnExit.Size = new System.Drawing.Size(75, 23); this.btnExit.TabIndex = 6; this.btnExit.Text = "Exit"; this.btnExit.UseVisualStyleBackColor = true; this.btnExit.Click += new System.EventHandler(this.btnExit_Click); // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(294, 56); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(32, 17); this.checkBox1.TabIndex = 7; this.checkBox1.Text = "1"; this.checkBox1.UseVisualStyleBackColor = true; this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Location = new System.Drawing.Point(294, 79); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(32, 17); this.checkBox2.TabIndex = 8; this.checkBox2.Text = "2"; this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); // // checkBox3 // this.checkBox3.AutoSize = true; this.checkBox3.Location = new System.Drawing.Point(294, 103); this.checkBox3.Name = "checkBox3"; this.checkBox3.Size = new System.Drawing.Size(32, 17); this.checkBox3.TabIndex = 9; this.checkBox3.Text = "3"; this.checkBox3.UseVisualStyleBackColor = true; this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged); // // checkBox4 // this.checkBox4.AutoSize = true; this.checkBox4.Location = new System.Drawing.Point(294, 129); this.checkBox4.Name = "checkBox4"; this.checkBox4.Size = new System.Drawing.Size(32, 17); this.checkBox4.TabIndex = 10; this.checkBox4.Text = "4"; this.checkBox4.UseVisualStyleBackColor = true; this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged); // // checkBox5 // this.checkBox5.AutoSize = true; this.checkBox5.Location = new System.Drawing.Point(294, 152); this.checkBox5.Name = "checkBox5"; this.checkBox5.Size = new System.Drawing.Size(32, 17); this.checkBox5.TabIndex = 11; this.checkBox5.Text = "5"; this.checkBox5.UseVisualStyleBackColor = true; this.checkBox5.CheckedChanged += new System.EventHandler(this.checkBox5_CheckedChanged); // // checkBox6 // this.checkBox6.AutoSize = true; this.checkBox6.Location = new System.Drawing.Point(362, 56); this.checkBox6.Name = "checkBox6"; this.checkBox6.Size = new System.Drawing.Size(32, 17); this.checkBox6.TabIndex = 12; this.checkBox6.Text = "6"; this.checkBox6.UseVisualStyleBackColor = true; this.checkBox6.CheckedChanged += new System.EventHandler(this.checkBox6_CheckedChanged); // // checkBox7 // this.checkBox7.AutoSize = true; this.checkBox7.Location = new System.Drawing.Point(362, 79); this.checkBox7.Name = "checkBox7"; this.checkBox7.Size = new System.Drawing.Size(32, 17); this.checkBox7.TabIndex = 13; this.checkBox7.Text = "7"; this.checkBox7.UseVisualStyleBackColor = true; this.checkBox7.CheckedChanged += new System.EventHandler(this.checkBox7_CheckedChanged); // // checkBox8 // this.checkBox8.AutoSize = true; this.checkBox8.Location = new System.Drawing.Point(362, 103); this.checkBox8.Name = "checkBox8"; this.checkBox8.Size = new System.Drawing.Size(32, 17); this.checkBox8.TabIndex = 14; this.checkBox8.Text = "8"; this.checkBox8.UseVisualStyleBackColor = true; this.checkBox8.CheckedChanged += new System.EventHandler(this.checkBox8_CheckedChanged); // // checkBox9 // this.checkBox9.AutoSize = true; this.checkBox9.Location = new System.Drawing.Point(362, 128); this.checkBox9.Name = "checkBox9"; this.checkBox9.Size = new System.Drawing.Size(32, 17); this.checkBox9.TabIndex = 15; this.checkBox9.Text = "9"; this.checkBox9.UseVisualStyleBackColor = true; this.checkBox9.CheckedChanged += new System.EventHandler(this.checkBox9_CheckedChanged); // // checkBox10 // this.checkBox10.AutoSize = true; this.checkBox10.Location = new System.Drawing.Point(362, 152); this.checkBox10.Name = "checkBox10"; this.checkBox10.Size = new System.Drawing.Size(38, 17); this.checkBox10.TabIndex = 16; this.checkBox10.Text = "10"; this.checkBox10.UseVisualStyleBackColor = true; this.checkBox10.CheckedChanged += new System.EventHandler(this.checkBox10_CheckedChanged); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(272, 22); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(57, 13); this.label1.TabIndex = 17; this.label1.Text = "First Class:"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(335, 22); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(75, 13); this.label2.TabIndex = 18; this.label2.Text = "Second Class:"; // // frmReservations // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(484, 261); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.checkBox10); this.Controls.Add(this.checkBox9); this.Controls.Add(this.checkBox8); this.Controls.Add(this.checkBox7); this.Controls.Add(this.checkBox6); this.Controls.Add(this.checkBox5); this.Controls.Add(this.checkBox4); this.Controls.Add(this.checkBox3); this.Controls.Add(this.checkBox2); this.Controls.Add(this.checkBox1); this.Controls.Add(this.btnExit); this.Controls.Add(this.lblAirplaneFull); this.Controls.Add(this.lblMessage); this.Controls.Add(this.btnReservations); this.Controls.Add(this.rdbnEconomyClass); this.Controls.Add(this.rdbnFirstClass); this.Controls.Add(this.lblAirlineReserve); this.Name = "frmReservations"; this.Text = "Airline Reservations"; this.ResumeLayout(false); this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label lblAirlineReserve; private System.Windows.Forms.RadioButton rdbnFirstClass; private System.Windows.Forms.RadioButton rdbnEconomyClass; private System.Windows.Forms.Button btnReservations; private System.Windows.Forms.Label lblMessage; private System.Windows.Forms.Label lblAirplaneFull; private System.Windows.Forms.Button btnExit; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.CheckBox checkBox2; private System.Windows.Forms.CheckBox checkBox3; private System.Windows.Forms.CheckBox checkBox4; private System.Windows.Forms.CheckBox checkBox5; private System.Windows.Forms.CheckBox checkBox6; private System.Windows.Forms.CheckBox checkBox7; private System.Windows.Forms.CheckBox checkBox8; private System.Windows.Forms.CheckBox checkBox9; private System.Windows.Forms.CheckBox checkBox10; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; } }

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 AirlinesReservation { public partial class frmReservations : Form { //Set values, strings, static int, and bools. int i = 0; private static int First_Class_Number_OfSeats = 5; private static int Economy_Class_Number_OfSeats = 5; private static int totalTicketSales = 1; bool[] frstSeats = new bool[First_Class_Number_OfSeats]; bool[] ecoSeats = new bool[Economy_Class_Number_OfSeats]; string seatChoice; int frstCount = 1; int ecoCount = 1;

public frmReservations() { InitializeComponent(); } public int GetAllSeats() { //Return seats for both classes. return First_Class_Number_OfSeats + Economy_Class_Number_OfSeats; }

public int GetFirstClassSeats() { //Return number of first class seats. return First_Class_Number_OfSeats; } public int GetEconomyClassSeats() { //Return number of economy seats. return Economy_Class_Number_OfSeats; }

public bool IsEconomyClassAvailable(int ecoSeats) { //Check for economy class seating. bool value = false; if(ecoSeats > GetEconomyClassSeats()) { value = false; } else { value = true; } return value; }

public bool IsFirstClassAvailable(int firstSeats) { //Check for first class availability. bool value = false; if(firstSeats > GetFirstClassSeats()) { value = false; } else { value = true; } return value; }

public void ReserveFirstClassAnySeat(int frstSeats) { //Counter for first class seats. if(totalTicketSales == 11) { lblAirplaneFull.Visible = true; lblMessage.Visible = false; }

if(frstSeats > GetFirstClassSeats()) { lblMessage.Text = "First class full, economy available";

} if(frstSeats == GetFirstClassSeats()) { lblAirplaneFull.Text = "Sorry expensive seats taken, 3 hour wait."; } else { if(IsFirstClassAvailable(frstSeats)) { ecoSeats[i] = false; lblMessage.Text = " Reserve seat in economy class"; lblMessage.Visible = true; totalTicketSales++; }

} }

public void ReserveEconomyClassAnySeat(int ecoSeats) { //Counter for economy class seats. if(totalTicketSales == 11) { lblAirplaneFull.Visible = true; lblMessage.Visible = false;

} if(ecoSeats > GetEconomyClassSeats()) { lblMessage.Text = "Economy is full, first class available.";

} if(ecoSeats == GetEconomyClassSeats()) { lblAirplaneFull.Text = "This plane is full people, 3 hour wait."; } else { if(IsEconomyClassAvailable(ecoSeats)) { frstSeats[i] = false; lblMessage.Text = " Reserved seat in economy class"; lblMessage.Visible = true; totalTicketSales++;

} } }

private void btnReservations_Click(object sender, EventArgs e) { //Reservation counter for economy and first class. for(int i = 0; i

if(seatChoice == "First Class") { //First class choice counter ReserveFirstClassAnySeat(frstCount); frstCount++; } else { ReserveEconomyClassAnySeat(ecoCount); ecoCount++; } }

private void rdbnFirstClass_CheckedChanged(object sender, EventArgs e) { //Select first class radio button. seatChoice = rdbnFirstClass.Text; }

private void rdbnEconomyClass_CheckedChanged(object sender, EventArgs e) { //Select economy radio button. seatChoice = rdbnEconomyClass.Text; }

private void btnExit_Click(object sender, EventArgs e) { //Close application. this.Close(); }

private void checkBox1_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox2_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox3_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox4_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox5_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox6_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox7_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox8_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox9_CheckedChanged(object sender, EventArgs e) {

}

private void checkBox10_CheckedChanged(object sender, EventArgs e) {

} } }

ne Reservations Airline Reservation O First Class O Economy Class Reservations Exit First Class Second Class 10 X

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. What are the pros and cons of diversity for an organisation?

Answered: 1 week ago

Question

1. Explain the concept of diversity and equality in the workplace.

Answered: 1 week ago