Question
Airline Reservation Assignment Okay In this programming class we have been woking on developing a program that allows the user to select a class and
Okay In this programming class we have been woking on developing a program that allows the user to select a class and then it will assign the user to a seat in that class. This program uses a GUI and will display with a check box what seat they are assigned to.
Below I have a code that is working ( so please try it out and see how it works before you do anything)
This week my instructor want me to make some changes to this program (see instructions below)
Also below is a picture of the GUI allong with the code to go along with it. Note: this program is made up of multipule classes.
Please Include a screen shot of the working code if you can
---------------------------------------------------------------
Instructions for assignment
Currently, you already must have a fully working GUI-based program with two radio-buttons, some labels, and textboxes and images. Your program already should assign a first available seat in Economy or First Class based on the user selection. For this version: Your program absolutelymustuse array of booleans to keep information about seats (false - not selected, true - selected). Your program should use separate classes for logic and GUI front-end. Must implement all methods in Reserver class, functionally similar to provided before. The GUI class should access Reserver via interface IReservable, like IReservable r = new Reserver(). Must use checkboxes to represent seats. Make checkboxes checked and disabled after selection. Must have background image (not mine). Must display messages in popup or on the main Form. Must include Reset button to start over. Reserver class must implement IResersable interface. Some methods will not be used yet.
interface IReservable
{
//returns true if at least one seat is available in First class
bool IsFirstClassAvailable();
//returns true if at least one seat is available in Economy class
bool IsEconomyClassAvailable();
///returns assigned first available(!) seat number in First class
int ReserveFirstClassAnySeat();
///returns assigned first available(!) seat number in Economy class
int ReserveEconomyClassAnySeat();
///assigns specific seat number in First class
void ReserveFirstClassSeat(int seat);
///assigns specific seat number in Economy class
void ReserveEconomyClassSeat(int seat);
///un-assigns specific seat number in First class
void UnreserveFirstClassSeat(int seat);
///un-assigns specific seat number in Economy class
void UnreserveEconomyClassSeat(int seat);
///gets all seats assigned and un-assigned in First class
bool[] GetFirstClassSeats();
///gets all seats assigned and un-assigned in Economy class
bool[] GetEconomyClassSeats();
//YOU MAY NEED SOMETHING FOR RESET
}
New: When a seat is selected, MessageBox should display "Selected Seat: 2" (obviously, 2 is just an example). You can make this massage more informative. This message should be associated with checkboxes using events. Basically, you will need to implement CheckChanged_click.
private void AirlineGUI_Load(object sender, EventArgs e)
{
//http://www.colorpicker.com/
Color c = Color.FromArgb(207, 219, 227); //up to 256
this.BackColor = c;
foreach (Control control in this.Controls)
{
if (control.GetType() == typeof(CheckBox))
{
((CheckBox)control).CheckedChanged += new EventHandler(this.CheckChanged_click);
}
}
}
New: Each public method must have proper XML documentation.
-----------------------------------------------------------------------------------------------------
Now here is the code that I have that will need to be modified to the instructions above (MUST BE IN C#. You may have to add a class or interface
Form1.cs (The main Display screen)
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 EX_3_Airline_Reservation_System { public partial class AirlineReservationGUI : Form {
Reserver reserver = null; public AirlineReservationGUI()
{ this.reserver = new Reserver(); InitializeComponent(); } private void AirlineReservationGUI_Load(object sender, EventArgs e) { //http://www.colorpicker.com/ Color c = Color.FromArgb(172, 172, 172); //up to 256
this.BackColor = c; }
private void btnReserve_Click(object sender, EventArgs e) { if (rdoFirst.Checked) { handleFirstClass(); } else //Economy { handleEconomyClass(); } }
private void handleFirstClass() {
if (reserver.isFirstClassAvailable()) { int seat = reserver.reserveFirstClassAnySeat();
updateSeatsMap(seat); } else if (reserver.isEconomyClassAvailable()) { MessageBox.Show("First Class unavailable, please try economy."); } else { MessageBox.Show("All seats are taken, next flight in 3 hours."); } }
private void handleEconomyClass() { if (reserver.isEconomyClassAvailable()) { int seat = reserver.reserveEconomyClassAnySeat(); updateSeatsMap(seat + 5); //shift } else if (reserver.isFirstClassAvailable()) { MessageBox.Show("Economy Class unavailable, please try First class."); } else { MessageBox.Show("All seats are taken, next flight in 3 hours."); } }
private void updateSeatsMap(int seat) { seat++; if (seat == 1) { chkSeat1.Checked = true; chkSeat1.Enabled = false; }
if (seat == 2) { chkSeat2.Checked = true; chkSeat2.Enabled = false; }
if (seat == 3) { chkSeat3.Checked = true; chkSeat3.Enabled = false; }
if (seat == 4) { chkSeat4.Checked = true; chkSeat4.Enabled = false; }
if (seat == 5) { chkSeat5.Checked = true; chkSeat5.Enabled = false; } if (seat == 6) { chkSeat6.Checked = true; chkSeat6.Enabled = false; }
if (seat == 7) { chkSeat7.Checked = true; chkSeat7.Enabled = false; }
if (seat == 8) { chkSeat8.Checked = true; chkSeat8.Enabled = false; }
if (seat == 9) { chkSeat9.Checked = true; chkSeat9.Enabled = false; }
if (seat == 10) { chkSeat10.Checked = true; chkSeat10.Enabled = false; } }
private void btnRestart_Click(object sender, EventArgs e) { reserver.resetFirstClass(); reserver.resetEconomyClass(); foreach (Control control in this.Controls) { if (control.GetType() == typeof(CheckBox)) { if (control.Name.StartsWith("chkSeat")) //can be other checkboxes { ((CheckBox)control).Checked = false; ((CheckBox)control).Enabled = true; } } }
} } }
--------------------------------------------------------------------------------
Reserver.cs (Class/ The behind the scenes shit)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace EX_3_Airline_Reservation_System { public class Reserver { private bool[] fseats = new bool[5]; private bool[] eseats = new bool[5];
public bool isFirstClassAvailable() { foreach (var seat in fseats) { if (seat == false) { return true; //available } } return false; //otherwise unavailable }
//same as First cluss, just different syntax public bool isEconomyClassAvailable() { for (int i = 0; i { if (eseats[i] == false) { return true; //available } } return false; //otherwise unavailable }
private bool[] getAllFirstSeats() { return fseats; }
private bool[] getAllEconomySeats() { return eseats; }
private bool getFirstClassSeatStatus(int seat) { //TODO if seat 4, throw exception return fseats[seat]; }
private bool getEconomyClassSeatStatus(int seat) { //TODO if seat 4, throw exception return eseats[seat]; }
//should preceeded with isFirstClassAvailable public int reserveFirstClassAnySeat() { for (int i = 0; i { if (fseats[i] == false) { fseats[i] = true; return i; //available seat number } } return -1; //otherwise unavailable } //should preceeded with isEconomyClassAvailable public int reserveEconomyClassAnySeat() { for (int i = 0; i { if (eseats[i] == false) { eseats[i] = true; return i; //available seat number } } return -1; //otherwise unavailable }
public int reserveFirstClassSeat(int seat) { if (fseats[seat] == false) { fseats[seat] = true; return seat; //confirmed }
return -1; //was not available }
public int unreserveFirstClassSeat(int seat) { if (fseats[seat] == true) { fseats[seat] = false; return seat; //confirmed }
return -1; //was not available } public int reserveEconomyClassSeat(int seat) { if (eseats[seat] == false) { eseats[seat] = true; return seat; //confirmed }
return -1; //was not available } public int unreserveEconomyClassSeat(int seat) { if (eseats[seat] == true) { eseats[seat] = false; return seat; //confirmed }
return -1; //was not available } public void resetFirstClass() { for (int i = 0; i { fseats[i] = false; } } public void resetEconomyClass() { for (int i = 0; i { eseats[i] = false; } } } }
---------------------------------------------------------------
So you know what to name the elements in Form1
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button btnRestart; private System.Windows.Forms.Button btnReserve; private System.Windows.Forms.RadioButton rdoFirst; private System.Windows.Forms.RadioButton rdoEconomy; private System.Windows.Forms.Label lblFirstClass; private System.Windows.Forms.Label lblEconomyClass; private System.Windows.Forms.CheckBox chkSeat1; private System.Windows.Forms.CheckBox chkSeat2; private System.Windows.Forms.CheckBox chkSeat3; private System.Windows.Forms.CheckBox chkSeat4; private System.Windows.Forms.CheckBox chkSeat5; private System.Windows.Forms.CheckBox chkSeat6; private System.Windows.Forms.CheckBox chkSeat7; private System.Windows.Forms.CheckBox chkSeat8; private System.Windows.Forms.CheckBox chkSeat9; private System.Windows.Forms.CheckBox chkSeat10;
-----------------------------------------------------------------------
I know this may take you a while but I greatly appreciate your help
First one to answer correctly gets a thumbs up!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started