Create a program for Smalltown Regional Airport Flights that accepts either an integer flight number or string airport code from the options in Figure 8-33. Pass the user’s entry to one of two overloaded GetFlightInfo() methods, and then display a returned string with all the flight details. For example, if 201 was input, the output would be: Flight #201 AUS Austin Scheduled at: 0710 (note that there should be two spaces between 'Austin' and 'Scheduled'). The method version that accepts an integer looks up the airport code, name, and time of flight; the version that accepts a string description looks up the flight number, airport name, and time. The methods return a message if the flight is not found. For example, if 100 was input, the output should be Flight #100 was not found. If no flights were scheduled for the airport code entered, for example MCO, the message displayed should be Flight to MCO was not found.
Create a program for Smalltown Regional Airport Flights that accepts either an integer flight number or string airport code from the options in Figure 8-33.
Pass the user’s entry to one of two overloaded GetFlightInfo() methods, and then display a returned string with all the flight details. For example, if 201 was input, the output would be: Flight #201 AUS Austin Scheduled at: 0710 (note that there should be two spaces between 'Austin' and 'Scheduled').
The method version that accepts an integer looks up the airport code, name, and time of flight; the version that accepts a string description looks up the flight number, airport name, and time.
The methods return a message if the flight is not found. For example, if 100 was input, the output should be Flight #100 was not found.
If no flights were scheduled for the airport code entered, for example MCO, the message displayed should be Flight to MCO was not found.
First, establish a structured repository to efficiently manage flight-related data. This repository should comprehensively catalog flight numbers, their associated airport codes, corresponding airport names, and the scheduled departure times for each flight.
Create a specialized function named get_flight_info. This function is tailored to receive a flight number as input and perform the following actions:
- Conduct an internal search within the data repository to ascertain if the specified flight number exists.
- In case of a successful match, retrieve and extract the relevant data elements, including the airport code, airport name, and the scheduled departure time.
- Present this information in an intelligible manner, encapsulating the flight number, airport code, airport name, and the designated departure time.
- Should no matching entry be identified, craft a response to communicate that the provided flight number does not correspond to any existing flight.
Complementing the previous function, create another specialized function called get_flight_info_by_code. This function is designed to accept an airport code as input and execute the following steps:
- Traverse the data repository systematically, seeking a flight associated with the provided airport code.
- Upon discovery of a matching flight, retrieve and format the pertinent details, which encompass the flight number, airport name, and the scheduled departure time.
- In scenarios where no corresponding flight data is found, generate a message to inform the user that no flights are scheduled to the specified airport code.
Instantiate an instance of the SmalltownRegionalAirport class. This instance will facilitate seamless access to the flight data within the system.
Enable user interaction by requesting input from the user, which can manifest as either a flight number or an airport code.
Deploy a systematic approach to interpret the user's input. Specifically, examine whether the provided input can be interpreted as an integer. The outcome of this examination determines whether the input represents a flight number or an airport code.
If the user input is conclusively identified as a flight number, initiate the get_flight_info function, supplying the flight number as an argument. Capture and retain the resultant data.
Conversely, if the user input aligns with an airport code, trigger the get_flight_info_by_code function with the airport code as input. Preserve the ensuing output for subsequent presentation.
Deliver the acquired result, which originates either from the execution of step 7 or step 8, in a user-friendly format. This presentation encapsulates exhaustive flight details or an apt notice if the entered input lacks a corresponding match in the data repository.
Conclude the algorithm, emphasizing its role in furnishing an efficient and user-centric mechanism for accessing flight information pertinent to Smalltown Regional Airport.
Step by step
Solved in 4 steps with 5 images