User interface language: English | Español

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

Question

An airport uses an object-oriented program to keep track of arrivals and departures of planes. There are many objects in this system and some are listed below.

The code below outlines the Arrival class used in this program.

public class Flight
{ private String id;
public String getId() {return this.id;}
// ... more variables, accessor and mutator methods
}

public class
Arrival
{ private Flight myFlight;
private String sta; // Scheduled Time of Arrival ("hh:mm")
private int runway;
private String gate;
private int delay;
private boolean landed;

public Arrival(Flight myFlight, String sta)
{ this.myFlight = myFlight;
this.sta = sta;
this.runway = 0;
this.gate = null;
this.delay = 0;
this.landed = false;
}

public void addDelay(int newDelay)
{ this.delay = newDelay;
}

public String getETA()
{ // calculates the Estimated Time of Arrival (ETA) of the flight
// by adding the delay to the sta and returning the result as a
// String ("hh:mm")
}

public int compareWith(String flightID)
{ if (myFlight.getID().equals(flightID)) { return 0; }
else { return 1; }
}

public int compareWith(Arrival anotherArrival)
{ // missing code
}

// ... plus accessor and mutator methods
}

The code below outlines part of the FlightManagement class used in this program.

For the purposes of this exam only arriving flights are being considered.

public class FlightManagement
{
private Arrival[] inbound; // array of inbound airplanes
private int last = -1; // index of last used entry

public
FlightManagement()
{ inbound = new Arrival[200];
}

public void
add(Arrival newArrival)
{ // missing code that adds the newArrival to the array inbound
// sorted by ETA, and updates last
}

private int search (String flightID)
{ // missing code that searches the array inbound and
// returns the index of the Arrival object with flightID
}

public Arrival remove(String flightID)
{ Arrival result;
int index = search(flightID);
result = inbound[index];
while (index < last)
{ inbound[index] = inbound[index + 1];
index++;
}
last--;
return result;
}

// ... many more methods
}

The method search in the FlightManagement class searches the array inbound and returns the index of the Arrival object with the given flightID.

Outline the general nature of an object.

[2]
a.i.

Describe two disadvantages of using Object Oriented Programming (OOP).

[4]
a.ii.

Outline one advantage of using modularity in program development.

[2]
a.iii.

State the relationship between the Flight object and the Arrival object.

[1]
b.

Construct a UML diagram to represent the Arrival object.

[4]
c.

Construct the method search implementing a linear search. Use the first compareWith() method in the Arrival object.

You may assume that an Arrival object with the given flightID exists in the array inbound.

[4]
d.

Outline one advantage of using a binary search.

[2]
e.i.

Outline one disadvantage of using a binary search.

[2]
e.ii.

Markscheme

Award up to [1] for each part of a suitable definition up to [2 max].
An object is an abstract entity;
and its components are data and/or actions;

a.i.

Award up to [1] for identifying each disadvantage and [1] for an elaboration of this disadvantage, up to [2 max].
Mark as [2] and [2].
Unsuitable for minor projects;
since OOP increases complexity for little gain;

OOP programs are larger than other programs;
and therefore slower;

OOP programs take more effort to construct;
because of the decomposition needed to achieve abstraction;

a.ii.

Award [1] for identifying an advantage and [1] for an elaboration of this advantage up to [2 max].

Example answers:
Faster development;
Because different programming teams can work on different modules;

Easier to debug;
Because the smaller modules will have fewer mistakes than one big program;

Easier to update (in the future);
Because it is easier to update a module than the full program;

Re-usability;
Modules can be stored in libraries and reused for different programs;

a.iii.

Award up to [1] for any indication of aggregation.

Example answer:
The Arrival object has/stores a Flight object;

b.

Award up to [4 max].
Award [1] for including 3 distinct sections.
Award [1] for including a component with all variables.
Award [1] for including a component with all listed methods.
Award [1] for indicating private/public using + / −.
Don't penalize the absence of accessor and mutator methods.

Example answer:

c.

Award up to [4 max].
Award [1] for a while loop.
Award [1] for correctly testing the flightID using compareWith().
Award [1] for incrementing the loop counter.
Award [1] for a return statement.

Example answer:

private int search(String flightID)
{ int i = 0;
while (inbound[i].compareWith(flightID) != 0)
{ i++; }
return i;
}
d.

Award up to [2 max].
Award [1] for identifying an advantage of using a binary search and [1] for an elaboration of the advantage up to [2 max].

Binary search is much faster than sequential search;
Because it halves the search range for every comparison;

e.i.

Award up to [2 max].
Award [1] for identifying a disadvantage of using a binary search and [1] for an elaboration of the disadvantage up to [2 max].

However, it is not applicable to unsorted data sets;
Because the data must be sorted first which adds to computational cost;

e.ii.

Examiners report

[N/A]
a.i.
[N/A]
a.ii.
[N/A]
a.iii.
[N/A]
b.
[N/A]
c.
[N/A]
d.
[N/A]
e.i.
[N/A]
e.ii.

Syllabus sections

Option D: Object-oriented programming » D.2 Features of OOP
Option D: Object-oriented programming

View options