Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

using javascript visual studio (Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. You have been asked

using javascript visual studio

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

Display the following alternatives: Please enter 1 for First Class or 2 for Economy. If the user types 1, your app should assign a seat in the first-class section (seats 15). If the user types 2, your app should assign a seat in the economy section (seats 610).

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. As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available.

Your app should never assign a seat that has already been assigned. When the economy section is full, your app should ask the person if its acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours."

i have this code for this question the only problem I have with this is when the seats are full for either first class or economy class after it prompted you to press 'Y' for yes and 'N' for no if you press other than those letters it will assign seats to whichever class is not full. I want to fix that but I couldn't figure out how. I want to code to say entry is not valid when they enter other than 'Y' or 'N'. thanks for the help.

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

namespace DuplicateElimination { class DupEliminator { static bool[] totalNumberOfSeats; // initalizing total seats static int assignedFirstClassSeats; static int assignedEconomyClassSeats;

static void Main(string[] args) { // console output Console.WriteLine(@" This is a program is an automated airline reservation system. passengers select their seat by pressing 1 for business class and 2 for economy class. if the first class is full you will be asked if you want to book in economy class if there are an available seat and vice versa. if no seats are available the application will let you know when the next flight is. make sure you enter capital letter 'Y' for yes and a capital letter 'N' for No.

"); totalNumberOfSeats = new bool[11]; // array int selectedClass = 0; // initalizing assigned seats

for (int i = 0; i <= 10; i++) // assigning initial seats to false totalNumberOfSeats[i] = false;

// assigning seats for (int i = 1; i <= 10; i++) { // console output Console.WriteLine("Enter 1 for First class or 2 for Economy class."); selectedClass = Convert.ToInt32(Console.ReadLine());

// discarding any inputs other than 1 and 2 form the user while (selectedClass < 1 || selectedClass > 2) { // console output Console.WriteLine("Please enter 1 for first class or 2 for Economy class."); selectedClass = Convert.ToInt32(Console.ReadLine()); } // when user assign first class seat if (selectedClass == 1) { // when first class is full and their are available seats in economy class if (assignedFirstClassSeats == 5 && assignedEconomyClassSeats < 5) { Console.WriteLine("First class seat is full. would you like a seat in Economy class? press uppercase 'Y' for yes and uppercase 'N' for no "); if (Console.ReadLine().Equals("N")) // if the passanger declines Economy class seats {

Console.WriteLine("Next plane leaves in 3 hours"); // console output i--; // decrement of one

} else { assignEconomyClass(); } } else if (assignedFirstClassSeats < 5) { assignFirstClass(); } } else { // when Economy class is full and their are available seats in first class if (assignedEconomyClassSeats == 5 && assignedFirstClassSeats < 5) { // console output Console.WriteLine("Economy class seat is full. would you like a seat in first class? press uppercase 'Y' for yes and uppercase 'N' for no "); if (Console.ReadLine().Equals("N")) { // console output Console.WriteLine("Next plane leaves in 3 hours"); i--; // decrement by one } else { assignFirstClass(); } } else { assignEconomyClass(); } } } // console output Console.WriteLine(); Console.WriteLine("Sorry, The plane is full. Next one leaves in 3 hours."); Console.ReadLine(); }

// new method for assigning first class seats static void assignFirstClass() { bool noDuplicate = false; Random rand = new Random(); int index = 0;

// generates seat number until their are no available seat while (!noDuplicate) { noDuplicate = true; index = rand.Next(1, 6); // holds the random generated seats if (totalNumberOfSeats[index] == true) noDuplicate = false; } totalNumberOfSeats[index] = true; // taken seats assignedFirstClassSeats++; // increase assigned class by one Console.WriteLine("assigned seat {0:N0}", index); // console output

} // new method for assigning second class seats static void assignEconomyClass() { bool noDuplicate = false; Random rand = new Random(); int index = 0;

// generates seat number until their are no available seat while (!noDuplicate) { noDuplicate = true; index = rand.Next(6, 11); if (totalNumberOfSeats[index] == true) noDuplicate = false; } totalNumberOfSeats[index] = true;// taken seats

assignedEconomyClassSeats++; // increase assigned class by one Console.WriteLine("assined seat {0:N0}", index); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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