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
booleanwhich could be added to the classRaceas 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
addSwimmersis used in both classesRaceandEvent.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
tempSwimmerandtempTime. -
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
Swimmerthat instantiates an object with parametersnameandschool. 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
swimmerarray 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
tempSwimmerto the arrayswimmersin 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
guestsof theLinkedListclass. -
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 thatguestsis 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
removeSchoolthat 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
staticin thePaymentclass. -
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
Paymentclass methodaddFoodItem()is passed aFoodItemobject 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, andItemclasses. 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);
wherewordis 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
Itemobject. -
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
Flightobject and theArrivalobject. -
18N.2.SL.TZ0.10d:
Construct the method
searchimplementing a linear search. Use the firstcompareWith()method in theArrivalobject.You may assume that an
Arrivalobject with the givenflightIDexists 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
Arrivalobject. -
18N.2.SL.TZ0.11b.i:
The
Arrivalobject has two methods namedcompareWith.Outline why calling the
compareWithmethod 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 arrayinboundthat have not yet landed and that have an ETA before a given timet. The timetis passed as aStringparameter. -
18N.2.SL.TZ0.12d:
When a flight is delayed, a method in
FlightManagementis 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 (
runway1andrunway2) 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 listresultwhich needs to be returned. You may assume thatrunway1andrunway2are accessible to the method and do not need to be passed. The original two lists are allowed to becomenullas a result of the merging.In answering this question, you may use the following methods from the JETS
LinkedListclass, 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 ofrunway1as 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 anewArrivalin the sorted arrayinbound. You may assume thatnewArrivalhas been instantiated and that the arrayinboundis 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
lineof 20Cartobjects. -
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
activein the UML of the classPOSlinewas 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
POSsystemandPOSlineobjects. -
19N.2.SL.TZ0.10f:
Construct the method
public void joinLine(Cart newCart)that adds anewCarttolinein the next emptyarraylocation. You may assume thatlineis not full. -
19N.2.SL.TZ0.12b:
Construct the code for a method
split(part of the classPOSsystem), that takes an existing, non-emptyPOSlineas 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
POSsystemwould be:POSline number2 = split(number1), wherenumber1is 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,POSlineandCart. 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 positionnfromlineby shifting down all the array entries bigger thann, before returning the indicatedCartobject. 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 firstCartNodeobject fromlist. The method must return theCartobject in that node ornulliflistis empty. -
19N.2.HL.TZ0.17c:
Sketch the linked list
listafter running the following code fragment wherecart1, cart2, cart3, cart4andcart5have 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 nthCartNodeobject fromlist. The method must return theCartobject in that node.You may assume that the nth
CartNodeobject 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
staticwhen declaring a variable. -
20N.2.SL.TZ0.10b:
Describe the relationship between the classes
VehicleandParkingArea. -
20N.2.SL.TZ0.10d.i:
Construct code to create an instance of the
Vehicleclass that has a registration ofX1234567. -
20N.2.SL.TZ0.10c:
Outline why it is necessary to use the keyword
thisin thesetBrokenmethod of theVehicleclass. -
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,MotorbikeandCarclasses. 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
staffRemoveCarmethod. -
20N.2.SL.TZ0.11d.i:
Construct the method
payin theVehicleclass that returns the admin fee stored in the variableAdminFeeif the vehicle has stayed for five hours or less; otherwise, it returns 0. -
20N.2.SL.TZ0.11d.ii:
Construct the method
payin theCarclass, where it uses thevehiclemethodpaybut adds the charge for the amount of time spent in the parking area. -
20N.2.SL.TZ0.11e:
The array
vehicles[]in theParkingAreaclass is used to store instances of theCarorMotorbikeclass.Outline why
Vehicleis a valid type for this array. -
20N.2.SL.TZ0.12a:
Describe, without writing code, any changes required to the
addVehiclemethod and theParkingAreaclass 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
removeVehiclemethod of theParkingAreaclass searches in the array for aVehicleobject with a specified registration plate, then removes it by setting that array index tonull.The method returns a reference to the
Vehicleobject that has been removed from the array, ornullif no matching registration plate was found.
Construct theremoveVehiclemethod. -
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
Pointsclass, 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 thePointsclass, 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
Visitsclass. -
18M.2.SL.TZ0.10e:
The attribute
statusNowis 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 thePointsclass, 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 anArrayListcontaining 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
Visitsclass. -
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, andItemclasses. 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
Flightobject and theArrivalobject. -
18N.2.SL.TZ0.10c:
Construct a UML diagram to represent the
Arrivalobject. -
19N.2.SL.TZ0.10a:
State the relationship between the
POSsystemandPOSlineobjects. -
19N.2.SL.TZ0.10b:
Draw a diagram to show the relationship between the objects
POSsystem,POSlineandCart. 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
activein the UML of the classPOSlinewas defined as a boolean data type. -
20N.2.SL.TZ0.10b:
Describe the relationship between the classes
VehicleandParkingArea. -
20N.2.SL.TZ0.11c:
Construct a UML diagram that shows the relationships between the
ParkingArea,Vehicle,MotorbikeandCarclasses. 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
Pointsclass, explain the OOP feature that makes it possible to successfully implement either of these methods. -
19M.2.SL.TZ0.11a:
The same method identifier
addSwimmersis used in both classesRaceandEvent.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
Arrivalobject has two methods namedcompareWith.Outline why calling the
compareWithmethod 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
statusNowis 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 thePointsclass, 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 thePointsclass, 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
booleanwhich could be added to the classRaceas indicated above. -
19M.2.SL.TZ0.10e:
Construct code for the constructor of the class
Swimmerthat instantiates an object with parametersnameandschool. 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
swimmerarray 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
tempSwimmerandtempTime. -
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
tempSwimmerto the arrayswimmersin 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
staticin thePaymentclass. -
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
Paymentclass methodaddFoodItem()is passed aFoodItemobject 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
searchimplementing a linear search. Use the firstcompareWith()method in theArrivalobject.You may assume that an
Arrivalobject with the givenflightIDexists 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 arrayinboundthat have not yet landed and that have an ETA before a given timet. The timetis passed as aStringparameter. -
18N.2.SL.TZ0.12c:
Without using a sorting algorithm, construct the method
add(Arrival newArrival)that inserts anewArrivalin the sorted arrayinbound. You may assume thatnewArrivalhas been instantiated and that the arrayinboundis not full. -
18N.2.SL.TZ0.12d:
When a flight is delayed, a method in
FlightManagementis 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
lineof 20Cartobjects. -
19N.2.SL.TZ0.10f:
Construct the method
public void joinLine(Cart newCart)that adds anewCarttolinein the next emptyarraylocation. You may assume thatlineis not full. -
19N.2.SL.TZ0.10g:
Construct the method
public Cart leaveLine(int n)that removes the cart at positionnfromlineby shifting down all the array entries bigger thann, before returning the indicatedCartobject. 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-emptyPOSlineas 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
POSsystemwould be:POSline number2 = split(number1), wherenumber1is 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
staticwhen declaring a variable. -
20N.2.SL.TZ0.10c:
Outline why it is necessary to use the keyword
thisin thesetBrokenmethod of theVehicleclass. -
20N.2.SL.TZ0.10d.i:
Construct code to create an instance of the
Vehicleclass 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
payin theVehicleclass that returns the admin fee stored in the variableAdminFeeif the vehicle has stayed for five hours or less; otherwise, it returns 0. -
20N.2.SL.TZ0.11d.ii:
Construct the method
payin theCarclass, where it uses thevehiclemethodpaybut adds the charge for the amount of time spent in the parking area. -
20N.2.SL.TZ0.11e:
The array
vehicles[]in theParkingAreaclass is used to store instances of theCarorMotorbikeclass.Outline why
Vehicleis a valid type for this array. -
20N.2.SL.TZ0.12a:
Describe, without writing code, any changes required to the
addVehiclemethod and theParkingAreaclass 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
removeVehiclemethod of theParkingAreaclass searches in the array for aVehicleobject with a specified registration plate, then removes it by setting that array index tonull.The method returns a reference to the
Vehicleobject that has been removed from the array, ornullif no matching registration plate was found.
Construct theremoveVehiclemethod.
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 anArrayListcontaining 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
guestsof theLinkedListclass. -
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 thatguestsis 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
removeSchoolthat 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
Itemobject. - 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);
wherewordis 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 ofrunway1as 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 (
runway1andrunway2) 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 listresultwhich needs to be returned. You may assume thatrunway1andrunway2are accessible to the method and do not need to be passed. The original two lists are allowed to becomenullas a result of the merging.In answering this question, you may use the following methods from the JETS
LinkedListclass, 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 firstCartNodeobject fromlist. The method must return theCartobject in that node ornulliflistis empty. -
19N.2.HL.TZ0.17c:
Sketch the linked list
listafter running the following code fragment wherecart1, cart2, cart3, cart4andcart5have 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 nthCartNodeobject fromlist. The method must return theCartobject in that node.You may assume that the nth
CartNodeobject 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
staffRemoveCarmethod. -
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.
