Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I could use some help witht this question! The code must be a C#application. Als

ID: 3841318 • Letter: I

Question

I could use some help witht this question!

The code must be a C#application. Also please make it basic as possible as I am a beginner. MUST BE A C# console application!!! PLEASE PLEASE MAKE IT AS BASIC AS POSSIBLE AND EXPLAIN WHAT YOU ARE DOING!!!

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

You can use Console application for now.

A small airline has just purchased a computer for its new automated
reservations system. You have been asked to develop the new system. You’re to write an
app to assign seats on each flight of the airline’s only plane (capacity: 10 seats).

Display the following alternatives:
Please type 1 for First Class and Please type 2 for Economy.
Enter 3 to exit (this is optional, but nice to have. Look at the TemperatureConverter for your inspiration)
If the user types 1, your application should assign a seat in the first-class section (seats 1–5).
If the user types 2, your application should assign a seat in the economy section (seats 6–10).

Use a one-dimensional array of type bool to represent the seating chart of the plane.
Initialize all the elements of the array to false to indicate that all the seats are empty (actually it is default).
As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available.
Your application should never assign a seat that has already been assigned!
When the economy section is full, your application should ask the user if it’s acceptable to be placed in the first-class section (and
vice versa).
But first check if seats are available in another class!
If the answer is yes, make the appropriate seat assignment. If no, display the message "Next flight
leaves in 3 hours."
Same if all seats are reserved, display the message "Next flight leaves in 3 hours."
Boolean seats:


Methods that might be helpful to implement:
public bool IsFirstClassAvailable()
public bool IsEconomyClassAvailable()
private bool[] GetAllSeats()
public bool[] GetFirstClassSeats()
public bool[] GetEconomyClassSeats()
public int ReserveFirstClassAnySeat()
public int ReserveEconomyClassAnySeat()

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

Sample of what the output should look like.

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

Thanks

Explanation / Answer

using System;
class AirlineResevationSystem
{
static void Main()
{
int seatsFirst, seatsEconomy, reserve, i = 0, j = 6;
bool[] seats = { false, false, false, false, false,
false, false, false, false, false }; // seating chart
Console.WriteLine("Welcome to Airline Reservation System."); // greet the user
while (true)
{
Console.WriteLine("There are " + checkFirstClass(out seatsFirst, seats) + " first class seats and " + checkEconomy(out seatsEconomy, seats) + " economy seats."); // check available seats
Console.WriteLine("Please enter 1 to reserve a first class seat or enter 2 to reserve an economy class seat or 0 to exit"); // promt user for input
reserve = Convert.ToInt32(Console.ReadLine()); // input from user
if (reserve == 1)
{
if (i > 5 || i == 5)
{
Console.WriteLine("There are no first class seats available. Would you like an economy class seat? Type 2 for yes and 0 to exit.");
reserve = Convert.ToInt32(Console.ReadLine());
}
else reserveFirstSeat(ref seats, ref i); // reserve first class seat
}
else if (reserve == 2)
{
if (j < 5 || j > 10)
{
Console.WriteLine("There are no economy seats available. Would you like a first class seat? Type 1 for yes and 0 to exit.");
reserve = Convert.ToInt32(Console.ReadLine());
}
else reserveEconomySeat(ref seats, ref j); // reserve economy class seat
}
else if (reserve == 0)
{
Console.WriteLine("Next flight leaves in three hours.");
break;
}
else
{
Console.WriteLine("Invalid entry. Please try again");
}
}
}
public static int checkFirstClass (out int seatsFirst, bool [] seats) // method to check available First Class seats
{
seatsFirst = 0;
for (int i = 0; i<5; i++)
{
if (seats[i] == false)
seatsFirst++;
}
return seatsFirst;
}
public static int checkEconomy (out int seatsEconomy, bool [] seats) // method to check available Economy seats
{
seatsEconomy = 0;
for (int i = 5; i<10; i++)
{
if (seats[i] == false)
seatsEconomy++;
}
return seatsEconomy;
}
public static void reserveFirstSeat (ref bool [] seats, ref int i) // reserve selected first class seat
{
if (i<5)
{
if (seats[i] == false)
{
seats[i] = true;
Console.WriteLine("You have successfully reserved a first class seat");
}
}
++i;
}
public static void reserveEconomySeat (ref bool [] seats, ref int j) // reserve selected economy class seat
{
if (j > 5 || j == 5 || j<10)
{
if (seats[j] == false)
{
seats[j] = true;
Console.WriteLine("You have successfully reserved an economy class seat");
}
}
++j;
}
}

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

Hope it Helps!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote