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 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
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Define the constructor for the class TFlight. Ensure it takes three parameters corresponding to flightNumber, city, and date. Assign these parameters to the respective attributes using the correct data types.
Step 2
2.1.2 Accessor methods:
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Implement the accessor methods getFlightNumber, getNumPassengers, and getCity. Each should return the appropriate attribute value.
Step 3
2.1.3 increasePassengers method:
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Define the increasePassengers method to accept an integer parameter. This method should increase the numPassengers attribute by this integer value and ensure it does not exceed a maximum limit.
Step 4
2.1.4 calcPreBooked method:
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Create the calcPreBooked method. This method should return the value of the numPassengers attribute as it represents the passengers booked for the flight.
Step 5
2.1.5 calcPercBooked method:
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Define calcPercBooked to calculate the percentage of booked passengers. Use the formula: ( \text{Percentage} = \frac{\text{numPassengers}}{\text{maximum capacity}} \times 100 ). Return the calculated percentage.
Step 6
2.1.6 toString method:
97%
121 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Implement the toString method to return a string representation of the flight object. Include the flight number, city, date, and number of passengers in the returned string.
Step 7
2.2.1 Button – Extract Flight Details:
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Create a method to extract flight details from combo box selections. This method should determine the position of the selected flight based on its flight number and copy the related attributes into variables.
Step 8
2.2.2 Button – setNumPassengers:
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Implement the setNumPassengers method for the object. If the specified flight exists, call increasePassengers with the new number of passengers.
Step 9
2.2.3 Button – Calculation of Fully Booked:
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Calculate the percentage of booked passengers using calcPercBooked. If the percentage exceeds 100%, display a message indicating that the flight is fully booked.