DP Computer Science Questionbank
D.3 Program development
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.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.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.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.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
. -
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.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.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.SL.TZ0.12a:
Define the term method signature.
-
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. -
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.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.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.
-
20N.2.SL.TZ0.10a:
Outline one effect of using the modifier
static
when declaring a variable. -
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.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.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.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”.