Photo AI
Question 2
SECTION B QUESTION 2: OBJECT-ORIENTATED PROGRAMMING Airlines store details of flights and passengers to assist staff in verifying information promptly. Do the fol... show full transcript
Step 1
Answer
To begin with, we create the constructor for the TFlight class. The constructor should include three parameters: flightNumber
, city
, and date
. Each parameter must be assigned to their respective attributes within the class. Ensure the data types are correct, matching string
for flightNumber
and city
, and date
as a DateTime
type. Finally, we need to call the setNumPassengers
method within the constructor.
Step 2
Answer
Next, we will implement the accessor methods for the attributes. Each method should have the appropriate return type matching the attribute types. For example:
getFlightNumber
should return a string
and retrieve the flightNumber
.getNumPassengers
should return an integer
for numPassengers
.getCity
should return a string
for city
.Step 3
Answer
We now need to create the increasePassengers
method. This method should accept one parameter of type integer
. Within the method, we will increase the value of numPassengers
by the parameter value. Ensure you validate that numPassengers
should not exceed the maximum capacity, possibly triggering an error or handling the overflow accordingly.
Step 4
Step 5
Answer
In the toString
method, we will create a string representation of the flight object. The method header should match the expected format. We need to concatenate the details of flightNumber
, city
, date
, and numPassengers
into a single formatted string output, ensuring clarity of the information.
Step 6
Answer
To extract flight details from the combobox, first retrieve the selected item and process it to find the flight number. Additionally, manage the position of the hash character properly to ensure retrieval of flightNumber
, city
, followed by copying these values into their respective variables.
Step 7
Answer
For this step, we will call the setNumPassengers
method and ensure the object is instantiated using the correct arguments. We need to incorporate error handling when reading a line from the text file and checking if the flight object corresponds to any line. Implement checks to validate the flight object and invoke the increasePassengers
method appropriately.
Step 8
Answer
Lastly, for displaying the total passengers, we will call calPercBooked
to calculate the booking percentage and display an appropriate message. If the percentage reaches 100%, provide a special message indicating "Fully Booked!". Finally, ensure to close the file properly to avoid any data loss.
Report Improved Results
Recommend to friends
Students Supported
Questions answered