Question: I could really use some help with this question! The code must be a C# form, and must be basic and easy to understand as

I could really use some help with this question!

The code must be a C# form, and must be basic and easy to understand as I am new to programming!

---------------------------------------------------------------------------------------

This is the same exercise Airline reservation with GUI. However, 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. You must have these methods implemented (others are up to you): public bool IsFirstClassAvailable() public bool IsEconomyClassAvailable() public void DisplayAllSeats() public bool[] GetAllSeats() public bool[] GetFirstClassSeats() public bool[] GetEconomyClassSeats() public int ReserveFirstClassAnySeat() public int ReserveEconomyClassAnySeat()

-------------------------------------------------------------------------

The code that needs to be modifed is below!

REMEMBER MUST BE FORM APPLICATION

using System;

//front end - subject for replacement in WinForm namespace AirlineReservationV1 { class AirlineReservation { private static int NO_CHOICE = 0; private static int FIRST_CLASS_CHOICE = 1; private static int ECONOMY_CLASS_CHOICE = 2; private static int EXIT_CHOICE = 3;

//re-usable class for Console and WinForm private Reserver reserver = new Reserver(); //class-level field. Instantiate Reserver class to use in this class public static void Main(string[] args) { AirlineReservation airline = new AirlineReservation(); airline.ProcessReservations();

//pause Console.ReadKey(); }

//starts here private void ProcessReservations() { int userChoice = NO_CHOICE; while (userChoice != EXIT_CHOICE) // { userChoice = GetUserInput();

if (userChoice == FIRST_CLASS_CHOICE) { HandleFirstClass(); } else if (userChoice == ECONOMY_CLASS_CHOICE) //very similar to First class { HandleEconomyClass(); } else //otherwise EXIT { Console.WriteLine("Thank you!"); } } }

private int GetUserInput() { int input = 0; //user input bool IsInputValid = false; //start with this, so loop will proceed at least once while (IsInputValid == false) { Console.WriteLine("1. Reserve FIRST Class"); //next enhancement: check first if it is available Console.WriteLine("2. Reserve ECONOMY Class"); //next enhancement: check first if it is available Console.WriteLine("3. EXIT"); try { input = Convert.ToInt32(Console.ReadLine()); if (input == FIRST_CLASS_CHOICE || input == ECONOMY_CLASS_CHOICE || input == EXIT_CHOICE) { IsInputValid = true; //out of the loop } else { Console.WriteLine("Invalid Selection. Re-enter 1, 2 or 3."); } } catch (Exception) //can be more specific { Console.WriteLine("Not a number."); } } return input; }

private void HandleFirstClass() { bool isEmptySeatInFirstClass = reserver.IsFirstClassAvailable();

if (isEmptySeatInFirstClass == true) { int firstClassSeatReserved = reserver.ReserveFirstClassAnySeat(); //reserve a seat Console.WriteLine("You reserved first class seat {0}", firstClassSeatReserved + 1); //+1 because return starts with 0 //Display all seats here, later } else //no first class seats, so check economy class { bool isEmptySeatInEconomyClass = reserver.IsEconomyClassAvailable(); if (isEmptySeatInEconomyClass == false) { Console.WriteLine("This plane is full. Next flight in 3 hours. Goodbye!"); } else { Console.WriteLine("FIRST class is full. ECONOMY class is still available." + " Do you want to reserve ECONOMY class?"); } } }

private void HandleEconomyClass() { bool isEmptySeatInEconomytClass = reserver.IsEconomyClassAvailable(); if (isEmptySeatInEconomytClass == true) { int economyClassSeatReserved = reserver.ReserveEconomyClassAnySeat(); Console.WriteLine("You reserved economy class seat {0}", economyClassSeatReserved + 1); //+1 because return starts with 0 //Display all seats here, later } else //no economy class seats, so check first class { bool isEmptySeatInFirstClass = reserver.IsFirstClassAvailable(); if (isEmptySeatInFirstClass == false) { Console.WriteLine("This plane is full. Next flight in 3 hours. Goodbye!"); } else { Console.WriteLine("ECONOMY class is full. FIRST class is still available." + " Do you want to reserve FIRST class?"); } } } } }

OR

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace AirlineReservationV1 { public class Reserver /*: IReservable will be used later*/ { private static int FIRST_CLASS_NUM_SEATS = 5; private static int ECONOMY_CLASS_NUM_SEATS = 5;

private bool[] fseats = new bool[FIRST_CLASS_NUM_SEATS]; //FIRST class seats private bool[] eseats = new bool[ECONOMY_CLASS_NUM_SEATS]; //ECONOMY class seats

public bool IsFirstClassAvailable() { foreach (var seat in fseats) //using foreach loop { if (seat == false) { return true; //available } } return false; //otherwise unavailable }

//same as first class, just different syntax public bool IsEconomyClassAvailable() { for (int i = 0; i < eseats.Length; i++) //using for loop { if (eseats[i] == false) { return true; //available } } return false; //otherwise unavailable }

private bool[] GetAllFirstSeats() { return fseats; }

private bool[] GetAllEconomySeats() { return eseats; }

//should be preceeded with IsFirstClassAvailable to avoid -1 //returns reserved seat public int ReserveFirstClassAnySeat() { for (int i = 0; i < fseats.Length; i++) { if (fseats[i] == false) { fseats[i] = true; return i; //reserved seat number } } return -1; //otherwise unavailable }

//should be preceeded with IsEconomyClassAvailable to avoid -1 //returns reserved seat public int ReserveEconomyClassAnySeat() { for (int i = 0; i < eseats.Length; i++) { if (eseats[i] == false) { eseats[i] = true; return i; //reserved seat number } } return -1; //otherwise unavailable }

//for displying seats public bool[] GetFirstClassSeats() { return fseats; }

//for displying seats public bool[] GetEconomyClassSeats() { return eseats; } }

}

-----------------------------------------------------------

Thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!