User interface language: English | Español

Date November 2018 Marks available 2 Reference code 18N.2.SL.TZ0.12
Level SL Paper 2 Time zone no time zone
Command term Define Question number 12 Adapted from N/A

Question

The array inbound in the FlightManagement class is sorted by Estimated Time of Arrival (ETA).

Define the term method signature.

[2]
a.

Construct a method showDelayed() that outputs the IDs of all delayed flights in the array inbound that have not yet landed and that have an ETA before a given time t. The time t is passed as a String parameter.

[4]
b.

Without using a sorting algorithm, construct the method add(Arrival newArrival) that inserts a newArrival in the sorted array inbound. You may assume that newArrival has been instantiated and that the array inbound is not full.

[6]
c.

When a flight is delayed, a method in FlightManagement is used to find and update the flight with the delay and to reorganize the array so that it remains sorted for the ETA.

Describe how this method would be implemented using the methods provided.

[4]
d.

Markscheme

Award up to [2 max].
[1 max] for any two out of three underlined key components.
[2 max] for all three key components.
Note: the return type is not part of the method signature.

Example answers:
The method name and all of its parameters and the type of these parameters.
The method name and the type of all of its parameters.

a.

Award up to [4 max].
Award [1] for a correct loop until last Arrival.
Award [1] for including correct test for ETA.
Award [1] for including correct test landed.
Award [1] for correctly using double dot notation in output statement.
Do not penalize incorrect use of accessor methods.

Example answers:

public void showDelayed(String t)
{ int i = 0;
while (i <= last)
{ if (inbound[i].getETA().compareTo(t) < 0)
{ if (!inbound[i].getLanded())
{ output(inbound[i].getMyFlight().getID());
}
i = i + 1
}
}
}

public void
showDelayed(String t)
{ int i = 0;
while ((i <= last) && (inbound[i].getETA().compareTo(t) < 0))
{ if (!inbound[i].landed)
{ output(inbound[i].myFlight.id);
}
i = i + 1
}
}

public void showDelayed(String t)
{ for (int i = 0; i <= last; i++)
{ if ((inbound[i].getETA().compareTo(t) < 0) &&
(!inbound[i].landed))
{ output(inbound[i].myFlight.id);
}
}
}
b.

Award up to [6 max].
Award [1] for a loop comparing newArrival to entries in inbound.
Award [1] for testing for the last entry.
Award [1] for good attempt a for loop in reverse order.
Award [1] for a fully correct for loop in reverse order.
Award [1] for correctly shifting elements in the array.
Award [1] for assigning newArrival.
Award [1] for incrementing last.

Example answer:

public void add(Arrival newArrival)
{   int i = 0;
    while ((i <= last)&&(inbound[i].compareWith(newArrival) < 0))
    { i++;
    }
    for (int j = last + 1; j>i; j--)
    {   inbound[j] = inbound[j - 1];
    }
    inbound[i] = newArrival;
    last++;
}

Alternative answer:

public void add(Arrival newArrival)
{
int i = 0;
while (i <= last)&&
(inbound[i].getETA().compareTo(newArrival.getETA()) < 0)
{ i++;
}
for (int j = last; j >= i; j--)
{ inbound[j + 1] = inbound[j];
}
inbound[i] = newArrival;
last++;
}
c.

Award up to [4 max].
Award [1] for declaring a variable of type Arrival.
Award [1] for calling remove (flightID).
Award [1] for calling addDelay(minutes).
Award [1] for adding the updated Arrival object to array inbound.
Award [1] for adding the update to the array inbound by calling add(update).

public void delay(String flightID, int minutes)
{
Arrival update = remove(flightID);
update.addDelay(minutes);
add(update);
}
d.

Examiners report

[N/A]
a.
[N/A]
b.
[N/A]
c.
[N/A]
d.

Syllabus sections

Option D: Object-oriented programming » D.3 Program development
Show 45 related questions
Option D: Object-oriented programming

View options