DP Computer Science Questionbank
Option D: Object-oriented programming
Description
[N/A]Directly related questions
-
19M.2.SL.TZ0.10a:
Define the term mutator method.
-
19M.2.SL.TZ0.10b:
State one additional instance variable of type
boolean
which could be added to the classRace
as indicated above. -
19M.2.SL.TZ0.10c:
With reference to both class UMLs provided above, distinguish between a class and an instantiation.
-
19M.2.SL.TZ0.10f:
Many swimmers in the event have names that cannot be represented using basic character sets such as ASCII.
Describe one feature of modern programming languages that allows the wide range of students’ names to be represented correctly.
-
19M.2.SL.TZ0.10d.ii:
Outline one disadvantage of using aggregation in this context.
-
19M.2.SL.TZ0.11a:
The same method identifier
addSwimmers
is used in both classesRace
andEvent
.Explain why this does not cause a conflict.
-
19M.2.SL.TZ0.11c:
Outline how method overriding can help to create the new class
FinalsOnlyEvent
. -
19M.2.SL.TZ0.12b:
Construct the code fragment for the given situation that will copy swimmers and times into two parallel arrays named
tempSwimmer
andtempTime
. -
19M.2.SL.TZ0.10d.i:
Outline one advantage of using aggregation in this context.
-
19M.2.SL.TZ0.10e:
Construct code for the constructor of the class
Swimmer
that instantiates an object with parametersname
andschool
. The event IDs should be set to “empty” and the times to 0.0 -
19M.2.SL.TZ0.11b:
Outline two advantages of the OOP feature “inheritance”.
-
19M.2.SL.TZ0.12a:
Sketch the resulting
swimmer
array infinals
. -
19M.2.SL.TZ0.12d:
Construct the code fragment that will copy the names of the 8 fastest swimmers in ascending order of time from the array
tempSwimmer
to the arrayswimmers
in the racefinals
. -
19M.2.HL.TZ0.17b:
Outline one reason why a linked list may be more suitable than a binary tree in this particular situation.
-
19M.2.HL.TZ0.17c.i:
Construct the code needed to instantiate an object
guests
of theLinkedList
class. -
19M.2.HL.TZ0.17a:
Define the term object reference.
-
19M.2.HL.TZ0.17c.ii:
Construct the code for the method
penultimate()
that returns the second to last element in the linked listguests
. You may assume thatguests
is locally accessible. -
19M.2.HL.TZ0.17d:
Using the data provided in the diagram, trace the call
recursive(0,'F')
, clearly showing the levels of recursion. -
19M.2.HL.TZ0.17e:
Outline one reason why the use of a recursive method may be inappropriate for linked lists.
-
19M.2.HL.TZ0.17f:
Due to unforeseen circumstances, schools may cancel their participation in an event at the last minute. Therefore, a method is needed to remove all the visiting students of one school from the linked list
guests
.Construct the method
removeSchool
that takes the name of a school as parameter and removes all students of that school from the listguests
. -
17N.2.SL.TZ0.10b:
State the implication of the use of the term
static
in thePayment
class. -
17N.2.SL.TZ0.10a:
Outline an alternative method of initializing these variables that would not require the use of the code in the constructor.
-
17N.2.SL.TZ0.10e:
The
Payment
class methodaddFoodItem()
is passed aFoodItem
object as a parameter.Construct the method
addFoodItem()
. -
17N.2.SL.TZ0.10c:
With reference to two examples from the classes in the resource, explain the benefits gained by the use of different data types.
-
17N.2.SL.TZ0.10d:
Describe the purpose of the following statement:
private FoodItem[] fi = new FoodItem[100]
-
17N.2.SL.TZ0.11b.i:
Construct statements, in code, that will print out the following: The number of drink items ordered by table 40.
-
17N.2.SL.TZ0.11a:
State the output after this code is executed.
-
17N.2.SL.TZ0.11b.ii:
Construct statements, in code, that will print out the following: The item code of the third food item ordered by table 2.
-
17N.2.SL.TZ0.12c:
The company that owns this restaurant also owns hotels, shops, and a car hire business. The programs that manage the finances of these different businesses include classes similar to the ones shown in this paper.
Explain how inheritance could be used as a tool to both improve the clarity of the design and to reduce the amount of code that needs to be written.
-
17N.2.SL.TZ0.11c:
Construct the method
findPrice()
. You may assume that the item exists in the array. -
17N.2.SL.TZ0.11d:
When a customer wishes to pay the bill, the method is called. If the bill was for table 10 then the following call would be made:
double finalBill = tables[10].calculateBill(Item[] pl)
;Construct the
calculateBill()
method. You should make use of any previously defined methods. -
17N.2.SL.TZ0.12a:
Construct a diagram showing the relationships between the
Payment
,FoodItem
,DrinkItem
, andItem
classes. You do not need to include the names of attributes or methods. -
17N.2.SL.TZ0.12b:
By making reference to any of the classes from 12(a), describe two benefits that a programming team would gain from the use of encapsulation.
- 17N.2.HL.TZ0.19a: Explain why recursion is a suitable tool to use when performing this check.
-
17N.2.HL.TZ0.18b:
Construct the method
changePrice()
. -
17N.2.HL.TZ0.19b:
The method
palindrome()
is called byboolean t = palindrome(word)
;
whereword
is a String variable.Without writing code, describe the recursive method
palindrome()
that returns whether or not a word is a palindrome. -
17N.2.HL.TZ0.18a:
Outline one benefit that the use of either of these choices will have over the original array structures.
-
17N.2.HL.TZ0.18c:
Explain how a binary tree structure would allow a more efficient search for the
Item
object. -
18N.2.SL.TZ0.10a.ii:
Describe two disadvantages of using Object Oriented Programming (OOP).
-
18N.2.SL.TZ0.10b:
State the relationship between the
Flight
object and theArrival
object. -
18N.2.SL.TZ0.10d:
Construct the method
search
implementing a linear search. Use the firstcompareWith()
method in theArrival
object.You may assume that an
Arrival
object with the givenflightID
exists in the arrayinbound
. -
18N.2.SL.TZ0.11a:
Outline the use of data-hiding as a security feature in OOP.
-
18N.2.SL.TZ0.10a.i:
Outline the general nature of an object.
-
18N.2.SL.TZ0.10a.iii:
Outline one advantage of using modularity in program development.
-
18N.2.SL.TZ0.10c:
Construct a UML diagram to represent the
Arrival
object. -
18N.2.SL.TZ0.11b.i:
The
Arrival
object has two methods namedcompareWith
.Outline why calling the
compareWith
method does not cause a conflict. - 18N.2.SL.TZ0.11b.ii: State the name of this OOP property.
-
18N.2.SL.TZ0.12b:
Construct a method
showDelayed()
that outputs the IDs of all delayed flights in the arrayinbound
that have not yet landed and that have an ETA before a given timet
. The timet
is passed as aString
parameter. -
18N.2.SL.TZ0.12d:
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. -
18N.2.HL.TZ0.16c:
Sketch the resulting linked list when an airplane with ID RO225, STA 12:05 and delay 0 is added to this list.
- 18N.2.HL.TZ0.16d.i: Define the term recursion.
-
18N.2.HL.TZ0.16e:
In case of bad weather it is possible that one of the runways has to be closed and the two linked lists (
runway1
andrunway2
) need to be merged using a methodmergeLists()
into one new linked listrunway
.Construct the method
public LinkedList<Arrival> mergeLists()
that merges the two sorted linked lists in to one sorted linked listresult
which needs to be returned. You may assume thatrunway1
andrunway2
are accessible to the method and do not need to be passed. The original two lists are allowed to becomenull
as a result of the merging.In answering this question, you may use the following methods from the JETS
LinkedList
class, in addition to any method provided or developed in this exam paper.addFirst(<object>) // adds the object at the head of the list
addLast(<object>) // adds the object at the tail of the list
getFirst() // returns the head object in the list
getLast() // returns the tail object in the list
removeFirst() // removes and returns the head object
removeLast() // removes and returns the tail object
size() // returns the number of objects in the list
isEmpty() // returns true if the list is empty -
18N.2.SL.TZ0.12a:
Define the term method signature.
-
18N.2.HL.TZ0.16d.ii:
Trace the call
process(runway1,0)
given the diagram ofrunway1
as drawn above. Copy and complete the following table. -
18N.2.SL.TZ0.12c:
Without using a sorting algorithm, construct the method
add(Arrival newArrival)
that inserts anewArrival
in the sorted arrayinbound
. You may assume thatnewArrival
has been instantiated and that the arrayinbound
is not full. -
18N.2.HL.TZ0.16b:
Evaluate the use of dynamic linked lists to static arrays when managing arriving airplanes.
-
18N.2.HL.TZ0.16a:
Outline an advantage of using a library.
-
19N.2.SL.TZ0.10d:
Distinguish between a class and an instantiation. You must make reference to the UML provided.
-
19N.2.SL.TZ0.10c:
Define the term identifier.
-
19N.2.SL.TZ0.10e:
State the code fragment that instantiates an array
line
of 20Cart
objects. -
19N.2.SL.TZ0.11b:
Explain one advantage of the OOP feature “inheritance” with reference to this scenario.
-
19N.2.SL.TZ0.11a:
Define the term inheritance.
-
19N.2.SL.TZ0.11e:
Outline two reasons why the use of multiple programming teams in different locations may be problematic when developing an integrated software solution.
-
19N.2.SL.TZ0.12a:
Outline why the variable
active
in the UML of the classPOSline
was defined as a boolean data type. -
19N.2.SL.TZ0.11c:
Describe two advantages of using libraries of classes.
-
19N.2.SL.TZ0.10a:
State the relationship between the
POSsystem
andPOSline
objects. -
19N.2.SL.TZ0.10f:
Construct the method
public void joinLine(Cart newCart)
that adds anewCart
toline
in the next emptyarray
location. You may assume thatline
is not full. -
19N.2.SL.TZ0.12b:
Construct the code for a method
split
(part of the classPOSsystem
), that takes an existing, non-emptyPOSline
as a parameter. It should copy every second cart from the original line into a new line. Afterwards it should delete every second cart from the original line.An example call in
POSsystem
would be:POSline number2 = split(number1)
, wherenumber1
is an existingPOSline
.You may use any method declared or developed.
-
19N.2.SL.TZ0.10b:
Draw a diagram to show the relationship between the objects
POSsystem
,POSline
andCart
. You are not required to draw a complete UML diagram. -
19N.2.SL.TZ0.10g:
Construct the method
public Cart leaveLine(int n)
that removes the cart at positionn
fromline
by shifting down all the array entries bigger thann
, before returning the indicatedCart
object. You may assume that a cart exists at positionn
. -
19N.2.SL.TZ0.12c:
As a result of the simulation, the company has decided to create a new POS system for their supermarkets.
There have been discussions about adapting existing open source code when developing modules of the new POS system.
Describe two ethical issues that may arise if modules of the new POS system are developed from open source code.
-
19N.2.HL.TZ0.17a:
Define the term object reference.
-
19N.2.HL.TZ0.17b:
Using object references, construct the method
public Cart removeFirst()
that removes the firstCartNode
object fromlist
. The method must return theCart
object in that node ornull
iflist
is empty. -
19N.2.HL.TZ0.17c:
Sketch the linked list
list
after running the following code fragment wherecart1, cart2, cart3, cart4
andcart5
have been instantiated as objects of the classCart
.POSlist queueList = new POSlist()
queueList.addLast(cart2);
queueList.addLast(cart1);
queueList.addLast(cart4);
queueList.removeFirst();
queueList.addLast(cart5);
queueList.addLast(cart3);
queueList.removeFirst(); -
19N.2.HL.TZ0.17d:
Outline one feature of the abstract data structure queue that makes it unsuitable to implement customers waiting in line.
-
19N.2.HL.TZ0.17e:
Using object references, construct the method
public Cart leaveList(int n)
that removes the nthCartNode
object fromlist
. The method must return theCart
object in that node.You may assume that the nth
CartNode
object exists in the list.
You may use any method declared or developed. -
19N.2.HL.TZ0.17f:
Explain the importance of using coding style and naming conventions when programming.
-
20N.2.SL.TZ0.10a:
Outline one effect of using the modifier
static
when declaring a variable. -
20N.2.SL.TZ0.10b:
Describe the relationship between the classes
Vehicle
andParkingArea
. -
20N.2.SL.TZ0.10d.i:
Construct code to create an instance of the
Vehicle
class that has a registration ofX1234567
. -
20N.2.SL.TZ0.10c:
Outline why it is necessary to use the keyword
this
in thesetBroken
method of theVehicle
class. -
20N.2.SL.TZ0.10d.ii:
Construct code that sets the colour of the object created in part (i) as black.
-
20N.2.HL.TZ0.16b:
Outline why searching for the registration plate in a binary tree would be faster than looking for it in the two-dimensional array.
-
20N.2.SL.TZ0.11c:
Construct a UML diagram that shows the relationships between the
ParkingArea
,Vehicle
,Motorbike
andCar
classes. There is no need to include the attributes or methods of each class. -
20N.2.HL.TZ0.16c:
Identify the steps that would be involved in taking the data from this two-dimensional array and creating a binary search tree.
-
20N.2.HL.TZ0.17b:
A stack can be implemented using an array or a singly linked list.
Compare the use of these two data structures for creating a stack. -
20N.2.SL.TZ0.11b:
Outline two differences between inheritance and aggregation.
-
20N.2.HL.TZ0.17a:
Construct the
staffRemoveCar
method. -
20N.2.SL.TZ0.11d.i:
Construct the method
pay
in theVehicle
class that returns the admin fee stored in the variableAdminFee
if the vehicle has stayed for five hours or less; otherwise, it returns 0. -
20N.2.SL.TZ0.11d.ii:
Construct the method
pay
in theCar
class, where it uses thevehicle
methodpay
but adds the charge for the amount of time spent in the parking area. -
20N.2.SL.TZ0.11e:
The array
vehicles[]
in theParkingArea
class is used to store instances of theCar
orMotorbike
class.Outline why
Vehicle
is a valid type for this array. -
20N.2.SL.TZ0.12a:
Describe, without writing code, any changes required to the
addVehicle
method and theParkingArea
class to make the new voucher scheme work. -
20N.2.SL.TZ0.12b:
Identify three other tests you might perform on the completed code to prove that it functions correctly.
-
20N.2.SL.TZ0.12c:
The
removeVehicle
method of theParkingArea
class searches in the array for aVehicle
object with a specified registration plate, then removes it by setting that array index tonull
.The method returns a reference to the
Vehicle
object that has been removed from the array, ornull
if no matching registration plate was found.
Construct theremoveVehicle
method. -
18M.2.SL.TZ0.10a:
With the use of two examples other than
private
, outline how the choice of this modifier affects the way in which these variables are accessed or used. -
18M.2.SL.TZ0.10b:
With reference to the two methods with the same name in the
Points
class, explain the OOP feature that makes it possible to successfully implement either of these methods. -
18M.2.SL.TZ0.11b.i:
State the output given by the following statement:
System.out.println(allPoints[2].getMemberId())
; -
18M.2.SL.TZ0.11b.iii:
State the output given by the following statement:
System.out.println(allPoints[1].getAllVisits(1).getDays())
; -
18M.2.SL.TZ0.11c:
Construct the method
calculateTotalPoints()
, in thePoints
class, which will calculate and return the total number of points awarded so far in the current year. - 18M.2.SL.TZ0.10c: State the status level that Tim has been assigned, for 2019, following these visits.
-
18M.2.SL.TZ0.11b.ii:
State the output given by the following statement:
System.out.println(allPoints[0].getBonusPoints())
; -
18M.2.SL.TZ0.10d:
State how an individual object can be identified using this array.
-
18M.2.SL.TZ0.11a:
Construct a UML diagram for the
Visits
class. -
18M.2.SL.TZ0.10e:
The attribute
statusNow
is assigned its correct value at the beginning of every year for existing members. It cannot be changed during the year.Construct the method
isGold()
in thePoints
class, which will return whether the current status is “Gold”. - 18M.2.HL.TZ0.18a: Outline why a linked list structure has been chosen for allCustomers.
-
18M.2.HL.TZ0.19b:
Copy and complete the following table to show the output when the method is called by:
recursionEx(3)
; -
18M.2.HL.TZ0.18b:
Construct the method
goldMails()
that will return anArrayList
containing the email addresses of all current “Gold” members. You should make use of any previously defined methods. -
18M.2.HL.TZ0.19a:
Identify two essential features of a recursive algorithm.
-
18M.2.HL.TZ0.19c:
Explain what would happen if the method was called by
recursionEx(-3)
. -
18M.2.HL.TZ0.19d:
Identify three features which should be included in either program code or UML diagrams to help programmers understand and modify programs in the future.
Sub sections and their related questions
D.1 Objects as a programming concept
-
18M.2.SL.TZ0.11a:
Construct a UML diagram for the
Visits
class. -
19M.2.SL.TZ0.10c:
With reference to both class UMLs provided above, distinguish between a class and an instantiation.
-
19M.2.SL.TZ0.10d.i:
Outline one advantage of using aggregation in this context.
-
19M.2.SL.TZ0.10d.ii:
Outline one disadvantage of using aggregation in this context.
-
17N.2.SL.TZ0.12a:
Construct a diagram showing the relationships between the
Payment
,FoodItem
,DrinkItem
, andItem
classes. You do not need to include the names of attributes or methods. -
18N.2.SL.TZ0.10a.i:
Outline the general nature of an object.
-
18N.2.SL.TZ0.10b:
State the relationship between the
Flight
object and theArrival
object. -
18N.2.SL.TZ0.10c:
Construct a UML diagram to represent the
Arrival
object. -
19N.2.SL.TZ0.10a:
State the relationship between the
POSsystem
andPOSline
objects. -
19N.2.SL.TZ0.10b:
Draw a diagram to show the relationship between the objects
POSsystem
,POSline
andCart
. You are not required to draw a complete UML diagram. -
19N.2.SL.TZ0.10d:
Distinguish between a class and an instantiation. You must make reference to the UML provided.
-
19N.2.SL.TZ0.12a:
Outline why the variable
active
in the UML of the classPOSline
was defined as a boolean data type. -
20N.2.SL.TZ0.10b:
Describe the relationship between the classes
Vehicle
andParkingArea
. -
20N.2.SL.TZ0.11c:
Construct a UML diagram that shows the relationships between the
ParkingArea
,Vehicle
,Motorbike
andCar
classes. There is no need to include the attributes or methods of each class.
D.2 Features of OOP
-
18M.2.SL.TZ0.10b:
With reference to the two methods with the same name in the
Points
class, explain the OOP feature that makes it possible to successfully implement either of these methods. -
19M.2.SL.TZ0.11a:
The same method identifier
addSwimmers
is used in both classesRace
andEvent
.Explain why this does not cause a conflict.
-
19M.2.SL.TZ0.11b:
Outline two advantages of the OOP feature “inheritance”.
-
19M.2.SL.TZ0.11c:
Outline how method overriding can help to create the new class
FinalsOnlyEvent
. -
17N.2.SL.TZ0.12b:
By making reference to any of the classes from 12(a), describe two benefits that a programming team would gain from the use of encapsulation.
-
17N.2.SL.TZ0.12c:
The company that owns this restaurant also owns hotels, shops, and a car hire business. The programs that manage the finances of these different businesses include classes similar to the ones shown in this paper.
Explain how inheritance could be used as a tool to both improve the clarity of the design and to reduce the amount of code that needs to be written.
-
18N.2.SL.TZ0.10a.ii:
Describe two disadvantages of using Object Oriented Programming (OOP).
-
18N.2.SL.TZ0.10a.iii:
Outline one advantage of using modularity in program development.
-
18N.2.SL.TZ0.11a:
Outline the use of data-hiding as a security feature in OOP.
-
18N.2.SL.TZ0.11b.i:
The
Arrival
object has two methods namedcompareWith
.Outline why calling the
compareWith
method does not cause a conflict. - 18N.2.SL.TZ0.11b.ii: State the name of this OOP property.
-
19N.2.SL.TZ0.11a:
Define the term inheritance.
-
19N.2.SL.TZ0.11b:
Explain one advantage of the OOP feature “inheritance” with reference to this scenario.
-
19N.2.SL.TZ0.11c:
Describe two advantages of using libraries of classes.
-
19N.2.SL.TZ0.11e:
Outline two reasons why the use of multiple programming teams in different locations may be problematic when developing an integrated software solution.
-
20N.2.SL.TZ0.11b:
Outline two differences between inheritance and aggregation.
D.3 Program development
-
18M.2.SL.TZ0.10a:
With the use of two examples other than
private
, outline how the choice of this modifier affects the way in which these variables are accessed or used. - 18M.2.SL.TZ0.10c: State the status level that Tim has been assigned, for 2019, following these visits.
-
18M.2.SL.TZ0.10d:
State how an individual object can be identified using this array.
-
18M.2.SL.TZ0.10e:
The attribute
statusNow
is assigned its correct value at the beginning of every year for existing members. It cannot be changed during the year.Construct the method
isGold()
in thePoints
class, which will return whether the current status is “Gold”. -
18M.2.SL.TZ0.11b.i:
State the output given by the following statement:
System.out.println(allPoints[2].getMemberId())
; -
18M.2.SL.TZ0.11b.ii:
State the output given by the following statement:
System.out.println(allPoints[0].getBonusPoints())
; -
18M.2.SL.TZ0.11b.iii:
State the output given by the following statement:
System.out.println(allPoints[1].getAllVisits(1).getDays())
; -
18M.2.SL.TZ0.11c:
Construct the method
calculateTotalPoints()
, in thePoints
class, which will calculate and return the total number of points awarded so far in the current year. -
19M.2.SL.TZ0.10a:
Define the term mutator method.
-
19M.2.SL.TZ0.10b:
State one additional instance variable of type
boolean
which could be added to the classRace
as indicated above. -
19M.2.SL.TZ0.10e:
Construct code for the constructor of the class
Swimmer
that instantiates an object with parametersname
andschool
. The event IDs should be set to “empty” and the times to 0.0 -
19M.2.SL.TZ0.10f:
Many swimmers in the event have names that cannot be represented using basic character sets such as ASCII.
Describe one feature of modern programming languages that allows the wide range of students’ names to be represented correctly.
-
19M.2.SL.TZ0.12a:
Sketch the resulting
swimmer
array infinals
. -
19M.2.SL.TZ0.12b:
Construct the code fragment for the given situation that will copy swimmers and times into two parallel arrays named
tempSwimmer
andtempTime
. -
19M.2.SL.TZ0.12d:
Construct the code fragment that will copy the names of the 8 fastest swimmers in ascending order of time from the array
tempSwimmer
to the arrayswimmers
in the racefinals
. -
17N.2.SL.TZ0.10a:
Outline an alternative method of initializing these variables that would not require the use of the code in the constructor.
-
17N.2.SL.TZ0.10b:
State the implication of the use of the term
static
in thePayment
class. -
17N.2.SL.TZ0.10c:
With reference to two examples from the classes in the resource, explain the benefits gained by the use of different data types.
-
17N.2.SL.TZ0.10d:
Describe the purpose of the following statement:
private FoodItem[] fi = new FoodItem[100]
-
17N.2.SL.TZ0.10e:
The
Payment
class methodaddFoodItem()
is passed aFoodItem
object as a parameter.Construct the method
addFoodItem()
. -
17N.2.SL.TZ0.11a:
State the output after this code is executed.
-
17N.2.SL.TZ0.11b.i:
Construct statements, in code, that will print out the following: The number of drink items ordered by table 40.
-
17N.2.SL.TZ0.11b.ii:
Construct statements, in code, that will print out the following: The item code of the third food item ordered by table 2.
-
17N.2.SL.TZ0.11c:
Construct the method
findPrice()
. You may assume that the item exists in the array. -
17N.2.SL.TZ0.11d:
When a customer wishes to pay the bill, the method is called. If the bill was for table 10 then the following call would be made:
double finalBill = tables[10].calculateBill(Item[] pl)
;Construct the
calculateBill()
method. You should make use of any previously defined methods. -
18N.2.SL.TZ0.10d:
Construct the method
search
implementing a linear search. Use the firstcompareWith()
method in theArrival
object.You may assume that an
Arrival
object with the givenflightID
exists in the arrayinbound
. -
18N.2.SL.TZ0.12a:
Define the term method signature.
-
18N.2.SL.TZ0.12b:
Construct a method
showDelayed()
that outputs the IDs of all delayed flights in the arrayinbound
that have not yet landed and that have an ETA before a given timet
. The timet
is passed as aString
parameter. -
18N.2.SL.TZ0.12c:
Without using a sorting algorithm, construct the method
add(Arrival newArrival)
that inserts anewArrival
in the sorted arrayinbound
. You may assume thatnewArrival
has been instantiated and that the arrayinbound
is not full. -
18N.2.SL.TZ0.12d:
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. -
19N.2.SL.TZ0.10c:
Define the term identifier.
-
19N.2.SL.TZ0.10e:
State the code fragment that instantiates an array
line
of 20Cart
objects. -
19N.2.SL.TZ0.10f:
Construct the method
public void joinLine(Cart newCart)
that adds anewCart
toline
in the next emptyarray
location. You may assume thatline
is not full. -
19N.2.SL.TZ0.10g:
Construct the method
public Cart leaveLine(int n)
that removes the cart at positionn
fromline
by shifting down all the array entries bigger thann
, before returning the indicatedCart
object. You may assume that a cart exists at positionn
. -
19N.2.SL.TZ0.12b:
Construct the code for a method
split
(part of the classPOSsystem
), that takes an existing, non-emptyPOSline
as a parameter. It should copy every second cart from the original line into a new line. Afterwards it should delete every second cart from the original line.An example call in
POSsystem
would be:POSline number2 = split(number1)
, wherenumber1
is an existingPOSline
.You may use any method declared or developed.
-
19N.2.SL.TZ0.12c:
As a result of the simulation, the company has decided to create a new POS system for their supermarkets.
There have been discussions about adapting existing open source code when developing modules of the new POS system.
Describe two ethical issues that may arise if modules of the new POS system are developed from open source code.
-
20N.2.SL.TZ0.10a:
Outline one effect of using the modifier
static
when declaring a variable. -
20N.2.SL.TZ0.10c:
Outline why it is necessary to use the keyword
this
in thesetBroken
method of theVehicle
class. -
20N.2.SL.TZ0.10d.i:
Construct code to create an instance of the
Vehicle
class that has a registration ofX1234567
. -
20N.2.SL.TZ0.10d.ii:
Construct code that sets the colour of the object created in part (i) as black.
-
20N.2.SL.TZ0.11d.i:
Construct the method
pay
in theVehicle
class that returns the admin fee stored in the variableAdminFee
if the vehicle has stayed for five hours or less; otherwise, it returns 0. -
20N.2.SL.TZ0.11d.ii:
Construct the method
pay
in theCar
class, where it uses thevehicle
methodpay
but adds the charge for the amount of time spent in the parking area. -
20N.2.SL.TZ0.11e:
The array
vehicles[]
in theParkingArea
class is used to store instances of theCar
orMotorbike
class.Outline why
Vehicle
is a valid type for this array. -
20N.2.SL.TZ0.12a:
Describe, without writing code, any changes required to the
addVehicle
method and theParkingArea
class to make the new voucher scheme work. -
20N.2.SL.TZ0.12b:
Identify three other tests you might perform on the completed code to prove that it functions correctly.
-
20N.2.SL.TZ0.12c:
The
removeVehicle
method of theParkingArea
class searches in the array for aVehicle
object with a specified registration plate, then removes it by setting that array index tonull
.The method returns a reference to the
Vehicle
object that has been removed from the array, ornull
if no matching registration plate was found.
Construct theremoveVehicle
method.
D.4 Advanced program development
- 18M.2.HL.TZ0.18a: Outline why a linked list structure has been chosen for allCustomers.
-
18M.2.HL.TZ0.18b:
Construct the method
goldMails()
that will return anArrayList
containing the email addresses of all current “Gold” members. You should make use of any previously defined methods. -
18M.2.HL.TZ0.19a:
Identify two essential features of a recursive algorithm.
-
18M.2.HL.TZ0.19b:
Copy and complete the following table to show the output when the method is called by:
recursionEx(3)
; -
18M.2.HL.TZ0.19c:
Explain what would happen if the method was called by
recursionEx(-3)
. -
18M.2.HL.TZ0.19d:
Identify three features which should be included in either program code or UML diagrams to help programmers understand and modify programs in the future.
-
19M.2.HL.TZ0.17a:
Define the term object reference.
-
19M.2.HL.TZ0.17b:
Outline one reason why a linked list may be more suitable than a binary tree in this particular situation.
-
19M.2.HL.TZ0.17c.i:
Construct the code needed to instantiate an object
guests
of theLinkedList
class. -
19M.2.HL.TZ0.17c.ii:
Construct the code for the method
penultimate()
that returns the second to last element in the linked listguests
. You may assume thatguests
is locally accessible. -
19M.2.HL.TZ0.17d:
Using the data provided in the diagram, trace the call
recursive(0,'F')
, clearly showing the levels of recursion. -
19M.2.HL.TZ0.17e:
Outline one reason why the use of a recursive method may be inappropriate for linked lists.
-
19M.2.HL.TZ0.17f:
Due to unforeseen circumstances, schools may cancel their participation in an event at the last minute. Therefore, a method is needed to remove all the visiting students of one school from the linked list
guests
.Construct the method
removeSchool
that takes the name of a school as parameter and removes all students of that school from the listguests
. -
17N.2.HL.TZ0.18a:
Outline one benefit that the use of either of these choices will have over the original array structures.
-
17N.2.HL.TZ0.18b:
Construct the method
changePrice()
. -
17N.2.HL.TZ0.18c:
Explain how a binary tree structure would allow a more efficient search for the
Item
object. - 17N.2.HL.TZ0.19a: Explain why recursion is a suitable tool to use when performing this check.
-
17N.2.HL.TZ0.19b:
The method
palindrome()
is called byboolean t = palindrome(word)
;
whereword
is a String variable.Without writing code, describe the recursive method
palindrome()
that returns whether or not a word is a palindrome. -
18N.2.HL.TZ0.16a:
Outline an advantage of using a library.
-
18N.2.HL.TZ0.16b:
Evaluate the use of dynamic linked lists to static arrays when managing arriving airplanes.
-
18N.2.HL.TZ0.16c:
Sketch the resulting linked list when an airplane with ID RO225, STA 12:05 and delay 0 is added to this list.
- 18N.2.HL.TZ0.16d.i: Define the term recursion.
-
18N.2.HL.TZ0.16d.ii:
Trace the call
process(runway1,0)
given the diagram ofrunway1
as drawn above. Copy and complete the following table. -
18N.2.HL.TZ0.16e:
In case of bad weather it is possible that one of the runways has to be closed and the two linked lists (
runway1
andrunway2
) need to be merged using a methodmergeLists()
into one new linked listrunway
.Construct the method
public LinkedList<Arrival> mergeLists()
that merges the two sorted linked lists in to one sorted linked listresult
which needs to be returned. You may assume thatrunway1
andrunway2
are accessible to the method and do not need to be passed. The original two lists are allowed to becomenull
as a result of the merging.In answering this question, you may use the following methods from the JETS
LinkedList
class, in addition to any method provided or developed in this exam paper.addFirst(<object>) // adds the object at the head of the list
addLast(<object>) // adds the object at the tail of the list
getFirst() // returns the head object in the list
getLast() // returns the tail object in the list
removeFirst() // removes and returns the head object
removeLast() // removes and returns the tail object
size() // returns the number of objects in the list
isEmpty() // returns true if the list is empty -
19N.2.HL.TZ0.17a:
Define the term object reference.
-
19N.2.HL.TZ0.17b:
Using object references, construct the method
public Cart removeFirst()
that removes the firstCartNode
object fromlist
. The method must return theCart
object in that node ornull
iflist
is empty. -
19N.2.HL.TZ0.17c:
Sketch the linked list
list
after running the following code fragment wherecart1, cart2, cart3, cart4
andcart5
have been instantiated as objects of the classCart
.POSlist queueList = new POSlist()
queueList.addLast(cart2);
queueList.addLast(cart1);
queueList.addLast(cart4);
queueList.removeFirst();
queueList.addLast(cart5);
queueList.addLast(cart3);
queueList.removeFirst(); -
19N.2.HL.TZ0.17d:
Outline one feature of the abstract data structure queue that makes it unsuitable to implement customers waiting in line.
-
19N.2.HL.TZ0.17e:
Using object references, construct the method
public Cart leaveList(int n)
that removes the nthCartNode
object fromlist
. The method must return theCart
object in that node.You may assume that the nth
CartNode
object exists in the list.
You may use any method declared or developed. -
19N.2.HL.TZ0.17f:
Explain the importance of using coding style and naming conventions when programming.
-
20N.2.HL.TZ0.16b:
Outline why searching for the registration plate in a binary tree would be faster than looking for it in the two-dimensional array.
-
20N.2.HL.TZ0.16c:
Identify the steps that would be involved in taking the data from this two-dimensional array and creating a binary search tree.
-
20N.2.HL.TZ0.17a:
Construct the
staffRemoveCar
method. -
20N.2.HL.TZ0.17b:
A stack can be implemented using an array or a singly linked list.
Compare the use of these two data structures for creating a stack.