Photo AI

SECTION B QUESTION 2: OBJECT-ORIENTATED PROGRAMMING Airlines store details of flights and passengers to assist staff in verifying information promptly - NSC Information Technology - Question 2 - 2017 - Paper 1

Question icon

Question 2

SECTION-B--QUESTION-2:-OBJECT-ORIENTATED-PROGRAMMING--Airlines-store-details-of-flights-and-passengers-to-assist-staff-in-verifying-information-promptly-NSC Information Technology-Question 2-2017-Paper 1.png

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

Worked Solution & Example Answer:SECTION B QUESTION 2: OBJECT-ORIENTATED PROGRAMMING Airlines store details of flights and passengers to assist staff in verifying information promptly - NSC Information Technology - Question 2 - 2017 - Paper 1

Step 1

2.1.1 Constructor:

96%

114 rated

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

2.1.2 Accessor methods:

99%

104 rated

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

2.1.3 increasePassengers method:

96%

101 rated

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

2.1.4 calPercBooked method:

98%

120 rated

Answer

The calPercBooked method calculates the percentage of booked seats. The formula for calculating this is: percentage=numPassengersmaximumCapacity×100percentage = \frac{numPassengers}{maximumCapacity} \times 100 Implement this method to return the calculated percentage to the caller.

Step 5

2.1.5 toString method:

97%

117 rated

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

2.2.1 Button – Question 2.2.1:

97%

121 rated

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

2.2.2 Button – Question 2.2.2:

96%

114 rated

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

2.2.3 Button – Question 2.2.3:

99%

104 rated

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.

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;