IB DP · PastPaper.sampleTitle

MetadataPastPaper.sampleTitle

Thinka Nov 2023 SL IB Diploma Programme-Style Mock — Computer Science

115 PastPaper.marks150 PastPaper.minutes2023
An original Thinka practice paper modelled on the structure and difficulty of the Nov 2023 SL IB Diploma Programme Computer Science paper. Not affiliated with or reproduced from IB.

Paper 1 Section A

Answer all questions. Short-answer questions testing core system architecture, computational thinking, and simple algorithms.
9 PastPaper.question · 24.93 PastPaper.marks
PastPaper.question 1 · Short Answer
2.77 PastPaper.marks
Identify two distinct disadvantages of providing user documentation exclusively in an online (internet-based) format.
PastPaper.showAnswers

PastPaper.workedSolution

Online-only documentation has several drawbacks: (1) Accessibility: Users must have an active internet connection to view the help documentation. If they have network connectivity issues, they cannot access it. (2) Server reliance: If the hosting web server experiences downtime or maintenance, the documentation becomes entirely unavailable to all users.

PastPaper.markingScheme

Award [1] mark for identifying each distinct disadvantage, up to [2] marks (capped at the total marks allocated).
- Award [1] mark for pointing out the necessity of an active internet connection / lack of offline accessibility.
- Award [1] mark for pointing out reliance on server availability / hosting uptime.
PastPaper.question 2 · Short Answer
2.77 PastPaper.marks
Outline the role of the Program Counter (PC) register during the fetch phase of the machine instruction cycle.
PastPaper.showAnswers

PastPaper.workedSolution

During the fetch phase, the CPU needs to retrieve the next instruction from RAM. The Program Counter (PC) holds the address of this next instruction. This address is placed onto the address bus (copied to the Memory Address Register / MAR) so the control unit can fetch the memory content. Immediately after this address is sent, the PC is incremented (usually by 1) so that it points to the subsequent instruction in the sequence.

PastPaper.markingScheme

Award [1] mark for stating that the PC holds/stores the address of the next instruction. Award [1] mark for explaining that this address is copied to the MAR or sent to the address bus. Award [1] mark for stating that the PC is incremented to point to the next sequential instruction (max 2.77 marks).
PastPaper.question 3 · Short Answer
2.77 PastPaper.marks
Explain one reason why packet switching is considered more efficient than circuit switching for transmitting data over a shared network.
PastPaper.showAnswers

PastPaper.workedSolution

In circuit switching, a dedicated physical path is established and reserved exclusively for the duration of the communication session. If no data is being sent at any moment, the bandwidth of that path is wasted. In packet switching, data is broken down into small packets that share communication channels dynamically with packets from other sessions. This avoids idle capacity and maximizes overall network utilization.

PastPaper.markingScheme

Award [1] mark for describing how packet switching shares channels dynamically rather than reserving a dedicated path. Award [1] mark for explaining that this prevents wasted bandwidth during periods of silence/idle transmission.
PastPaper.question 4 · Short Answer
2.77 PastPaper.marks
Consider the following algorithm segment:

A = 12
B = 15
loop while A != B
if A > B then
A = A - B
else
B = B - A
end if
end loop

Determine the final value of variable A when the loop terminates.
PastPaper.showAnswers

PastPaper.workedSolution

Let's trace the values of A and B through each iteration:
- Initial state: A = 12, B = 15. Since 12 != 15, we enter the loop.
- Iteration 1: Since A (12) is not greater than B (15), the 'else' block executes: B = B - A = 15 - 12 = 3. Now A = 12, B = 3.
- Iteration 2: Since A != B (12 != 3), we enter the loop. Since A (12) > B (3), the 'then' block executes: A = A - B = 12 - 3 = 9. Now A = 9, B = 3.
- Iteration 3: Since A != B (9 != 3), we enter the loop. Since A (9) > B (3), the 'then' block executes: A = A - B = 9 - 3 = 6. Now A = 6, B = 3.
- Iteration 4: Since A != B (6 != 3), we enter the loop. Since A (6) > B (3), the 'then' block executes: A = A - B = 6 - 3 = 3. Now A = 3, B = 3.
- Next check: Since A == B (3 == 3), the loop condition 'A != B' is false, and the loop terminates. The final value of A is 3.

PastPaper.markingScheme

Award [2.77] marks for the correct final answer: 3. Award [1] mark for demonstrating a correct trace step (e.g., showing B becoming 3 or A becoming 9).
PastPaper.question 5 · Short Answer
2.77 PastPaper.marks
During a system upgrade, an insurance company migrates its customer records from a legacy system to a new modern system. State two potential issues that could arise during this data migration process.
PastPaper.showAnswers

PastPaper.workedSolution

Data migration is highly sensitive and prone to several issues: (1) Data incompatibility: The legacy system's database schema or data formats may not align with the new system, resulting in truncation, invalid characters, or loss of context. (2) Data loss or corruption: System crashes, interrupted transmissions, or mapping errors during the migration process can cause critical records to be corrupted or lost entirely.

PastPaper.markingScheme

Award [1] mark for each valid issue identified, up to [2] marks. Valid points include: data incompatibility/format mismatch, data corruption, complete data loss, security/confidentiality breaches during transfer, and extended system downtime during transition.
PastPaper.question 6 · Short Answer
2.77 PastPaper.marks
Explain how cache memory improves the performance of a computer system's Central Processing Unit (CPU).
PastPaper.showAnswers

PastPaper.workedSolution

Cache memory consists of high-speed SRAM that is integrated directly onto or very close to the CPU chip. It holds copies of data and instructions from RAM that are frequently or recently accessed by the CPU. Because cache has much faster read/write speeds than primary memory (DRAM), retrieving instructions from cache eliminates memory access latency, allowing the CPU to execute instructions without waiting (fewer idle clock cycles/wait states).

PastPaper.markingScheme

Award [1] mark for stating that cache holds frequently/recently accessed instructions or data. Award [1] mark for explaining that cache has much faster access speeds than primary memory (RAM) and is closer to the CPU, reducing overall execution latency.
PastPaper.question 7 · Short Answer
2.77 PastPaper.marks
Identify two encryption protocols commonly used to secure wireless local area networks (WLANs).
PastPaper.showAnswers

PastPaper.workedSolution

Wireless local area networks (WLANs) are secured using standardized cryptographic protocols. WPA2 (Wi-Fi Protected Access 2) has been the industry standard for many years, using AES encryption. WPA3 (Wi-Fi Protected Access 3) is its newer, more secure successor which offers stronger encryption and protection against brute-force attacks. Other older, less secure protocols include WEP and WPA.

PastPaper.markingScheme

Award [1] mark for each valid wireless encryption protocol up to [2] marks. Acceptable answers include: WPA2, WPA3, WPA, WEP.
PastPaper.question 8 · Short Answer
2.77 PastPaper.marks
Outline how a 'flag' (or boolean variable) can be used to optimize a standard bubble sort algorithm.
PastPaper.showAnswers

PastPaper.workedSolution

A standard bubble sort will continue to compare adjacent items for a fixed number of passes even if the array becomes sorted early. To optimize this, a boolean variable (often named 'swapped') is set to 'false' at the beginning of each pass. During the pass, if any adjacent elements are swapped, the variable is changed to 'true'. At the end of the pass, if the variable remains 'false', it indicates no swaps were made, meaning the list is already fully sorted. The algorithm can then exit immediately, saving CPU time.

PastPaper.markingScheme

Award [1] mark for stating that the boolean variable tracks whether any swaps occurred during a pass. Award [1] mark for explaining that if no swaps occurred (flag is false), the loop terminates early because the array is sorted.
PastPaper.question 9 · Short Answer
2.77 PastPaper.marks
An organisation is choosing between a full backup strategy and an incremental backup strategy. Describe one advantage and one disadvantage of the incremental backup strategy compared to the full backup strategy.
PastPaper.showAnswers

PastPaper.workedSolution

An incremental backup only copies data that has changed since the last backup of any type. This results in much faster backup times and reduced storage space/network bandwidth consumption on a daily basis. However, in the event of system failure, data recovery is slower and more complex. To perform a complete restore, the system administrator must first restore the most recent full backup and then sequentially apply every single incremental backup made up to the point of failure. If any single incremental backup in the chain is corrupted or lost, the subsequent data cannot be fully recovered.

PastPaper.markingScheme

Award up to 3 marks: Award 1 mark for identifying a clear advantage of incremental backup (such as faster backup speed or reduced storage requirements during backup). Award 1 mark for identifying a clear disadvantage (such as slower restore time or higher risk of failure if one backup in the sequence is corrupted). Award 1 mark for explaining the underlying reason (such as only saving changes since the last backup, or requiring the assembly of the last full backup plus all subsequent incremental steps to restore).

Paper 1 Section B

Answer all questions. Long-form scenario and algorithmic questions.
3 PastPaper.question · 45 PastPaper.marks
PastPaper.question 1 · Structured scenario
15 PastPaper.marks
GreenValley International School is replacing its legacy desktop-based student information system (SIS) with a cloud-based software-as-a-service (SaaS) solution.

(a) Explain two disadvantages of using a SaaS-based model compared to hosting the software locally on the school's own servers. [4 marks]

(b) The school administration decides to use a parallel running implementation method rather than a direct changeover. Evaluate this decision. [4 marks]

(c) Outline two potential problems during the data migration process from the legacy system to the new system. [4 marks]

(d) Identify three different methods of providing user documentation for the new system. [3 marks]
PastPaper.showAnswers

PastPaper.workedSolution

(a) Disadvantages of SaaS:
1. Dependency on Internet Connectivity: If the school's internet connection fails, staff cannot access the student information system at all, whereas locally hosted systems remain accessible via local LAN.
2. Security and Data Privacy Concerns: Sensitive student files and personal details are stored on third-party servers, raising potential compliance issues with localized data protection laws.

(b) Parallel Running vs Direct Changeover:
Parallel running involves operating both the old and new systems simultaneously. This is highly reliable and low-risk because if the new SaaS platform experiences downtime or errors, the old system is still active, preventing data loss. However, it is very time-consuming and expensive as data has to be entered twice, heavily increasing the workload of school administrators. Direct changeover is fast and cheaper but introduces severe risks if the new system fails.

(c) Data Migration Problems:
1. Data Incompatibility: The database schemas between the legacy and SaaS systems may differ (e.g., date formats or combined name fields), leading to import errors.
2. Data Loss/Corruption: During transfer, some records may fail to migrate or become corrupted due to network errors or conversion mismatches.

(d) User Documentation Methods:
1. Printed manuals/booklets.
2. Online help pages/FAQs on the system website.
3. Interactive built-in tutorials or wizards within the software interface.

PastPaper.markingScheme

(a) [4 marks]
Award up to 2 marks for each disadvantage explained (1 mark for identifying, 1 mark for linking to the context of the school or SaaS).
- Dependency on reliable internet connection (1 mark); if the internet fails, school operations halt as access is lost (1 mark).
- Data security / privacy concerns (1 mark); hosting sensitive minor/student data on external servers may violate local data protection laws (1 mark).

(b) [4 marks]
Award marks for evaluation of parallel running:
- 1 mark for identifying low risk (fallback is available if the new system fails).
- 1 mark for noting high reliability/trust during the transition phase.
- 1 mark for identifying disadvantage: double entry of data / extra workload for school staff.
- 1 mark for a comparative conclusion (e.g., parallel running is safer for schools where data loss is unacceptable, despite the higher workload).

(c) [4 marks]
Award up to 2 marks for each problem outlined (1 mark for identification, 1 mark for description):
- Data incompatibility / format differences (1 mark); leading to mismatched fields in the new system (1 mark).
- Incomplete data transfer / lost records (1 mark); which can happen if there is data corruption or system timeouts during export/import (1 mark).

(d) [3 marks]
Award 1 mark for each valid method up to 3:
- Online FAQ / Wiki / Knowledge base
- Built-in help / interactive tutorials
- Printable PDF manuals / user guides
- Video tutorials / screencasts
PastPaper.question 2 · Structured scenario & pseudocode
15 PastPaper.marks
A temperature-monitoring system uses a 1D array of integers called TEMPS containing 6 values: [18, 22, 15, 25, 30, 12]. The following algorithm is used to sort this array:

```
N = 6
loop I from 0 to N - 2
loop J from 0 to N - I - 2
if TEMPS[J] > TEMPS[J+1] then
TEMP = TEMPS[J]
TEMPS[J] = TEMPS[J+1]
TEMPS[J+1] = TEMP
end if
end loop
end loop
```

(a) Construct a trace table showing the state of the array TEMPS at the end of each complete pass of the outer loop (i.e., when I completes its iteration, for I = 0, 1, 2, 3, 4). [6 marks]

(b) Outline the efficiency of this sorting algorithm in terms of Big O notation in both the best and worst cases. [3 marks]

(c) Write a pseudocode segment to search the sorted TEMPS array for a specific target temperature TARGET entered by the user. The algorithm should print "Found at index " followed by the index if it exists, or "Not Found" otherwise. Use a linear search. [6 marks]
PastPaper.showAnswers

PastPaper.workedSolution

(a) Trace table:
Initial TEMPS: [18, 22, 15, 25, 30, 12]

- Pass 1 (I = 0):
J runs from 0 to 4.
- J=0: TEMPS[0] (18) vs TEMPS[1] (22) -> no swap.
- J=1: TEMPS[1] (22) vs TEMPS[2] (15) -> swap -> [18, 15, 22, 25, 30, 12].
- J=2: TEMPS[2] (22) vs TEMPS[3] (25) -> no swap.
- J=3: TEMPS[3] (25) vs TEMPS[4] (30) -> no swap.
- J=4: TEMPS[4] (30) vs TEMPS[5] (12) -> swap -> [18, 15, 22, 25, 12, 30].
End of Pass 1 (I=0): TEMPS = [18, 15, 22, 25, 12, 30]

- Pass 2 (I = 1):
J runs from 0 to 3.
- J=0: 18 vs 15 -> swap -> [15, 18, 22, 25, 12, 30].
- J=1: 18 vs 22 -> no swap.
- J=2: 22 vs 25 -> no swap.
- J=3: 25 vs 12 -> swap -> [15, 18, 22, 12, 25, 30].
End of Pass 2 (I=1): TEMPS = [15, 18, 22, 12, 25, 30]

- Pass 3 (I = 2):
J runs from 0 to 2.
- J=0: 15 vs 18 -> no swap.
- J=1: 18 vs 22 -> no swap.
- J=2: 22 vs 12 -> swap -> [15, 18, 12, 22, 25, 30].
End of Pass 3 (I=2): TEMPS = [15, 18, 12, 22, 25, 30]

- Pass 4 (I = 3):
J runs from 0 to 1.
- J=0: 15 vs 18 -> no swap.
- J=1: 18 vs 12 -> swap -> [15, 12, 18, 22, 25, 30].
End of Pass 4 (I=3): TEMPS = [15, 12, 18, 22, 25, 30]

- Pass 5 (I = 4):
J runs from 0 to 0.
- J=0: 15 vs 12 -> swap -> [12, 15, 18, 22, 25, 30].
End of Pass 5 (I=4): TEMPS = [12, 15, 18, 22, 25, 30]

(b) Efficiency (Bubble Sort):
- Worst-case efficiency: \(O(N^2)\) because nested loops compare all elements regardless of initial state.
- Best-case efficiency: \(O(N^2)\) as written in this basic form because the loops execute fully even if the array starts sorted (Accept: \(O(N)\) if the candidate mentions that an optimized version uses a swap-tracking flag).

(c) Linear Search Pseudocode:
```
TARGET = input("Enter temperature: ")
FOUND = false
INDEX = -1
loop K from 0 to 5
if TEMPS[K] == TARGET then
FOUND = true
INDEX = K
end if
end loop

if FOUND == true then
output "Found at index ", INDEX
else
output "Not Found"
end if
```

PastPaper.markingScheme

(a) [6 marks]
Award 1 mark for the correct initial state representation and 1 mark for each correct outer loop pass state:
- Initial state: [18, 22, 15, 25, 30, 12]
- End of I=0: [18, 15, 22, 25, 12, 30] (1 mark)
- End of I=1: [15, 18, 22, 12, 25, 30] (1 mark)
- End of I=2: [15, 18, 12, 22, 25, 30] (1 mark)
- End of I=3: [15, 12, 18, 22, 25, 30] (1 mark)
- End of I=4: [12, 15, 18, 22, 25, 30] (1 mark)
- 1 mark for structured presentation mapping variable state steps.

(b) [3 marks]
- 1 mark for identifying Worst-case as \(O(N^2)\).
- 1 mark for identifying Best-case as \(O(N^2)\) for basic implementation (or \(O(N)\) with clear justification of optimization flag).
- 1 mark for explaining why (e.g., nested loops always execute comparisons of adjacent values).

(c) [6 marks]
- 1 mark for taking input or initializing the search target correctly.
- 1 mark for initializing a boolean flag (e.g., FOUND = false) and/or index tracker.
- 1 mark for a loop traversing the array indices (0 to 5).
- 1 mark for comparing each array element to TARGET correctly.
- 1 mark for setting the flag to true and capturing the index when found.
- 1 mark for outputting the correct messages (Found with index, or Not Found) depending on the flag condition.
PastPaper.question 3 · Structured scenario
15 PastPaper.marks
MedHealth Clinic is a local medical center that wants to establish a secure wireless local area network (WLAN) so that doctors can access patient electronic health records (EHR) on portable tablets while moving between consultation rooms.

(a) Define the terms protocol and data packet in the context of network communications. [4 marks]

(b) State two benefits of using a wireless network (WLAN) instead of a wired network (LAN) in this specific medical clinic scenario. [2 marks]

(c) Explain why using simple MAC address filtering is insufficient for securing the clinic's network. [3 marks]

(d) Explain how a Virtual Private Network (VPN) would allow a doctor to securely access patient records from home, referring to tunneling and encryption. [6 marks]
PastPaper.showAnswers

PastPaper.workedSolution

(a) Definitions:
- Protocol: A set of standardized rules that govern how data is formatted, transmitted, and received across a network to ensure compatibility between different devices.
- Data packet: A basic unit of data formatted for transmission over a network, containing both control information (such as source/destination addresses) and payload (the actual data).

(b) Benefits of WLAN in clinic:
1. Mobility: Doctors can carry tablets seamlessly from one consultation room to another without losing access to patient records.
2. Less physical clutter/hazards: No Ethernet cables running across clinical floors, reducing physical tripping hazards for patients and staff.

(c) Inadequacy of MAC address filtering:
MAC address filtering only allows registered network cards to connect. However, MAC addresses are transmitted in plain text during connection handshakes. An eavesdropper can easily capture an authorized MAC address using packet sniffing software and spoof (clone) it onto their own device, bypassing the filter entirely.

(d) VPN Explanation:
A VPN creates a secure connection over the public internet between the doctor's home device and the clinic's server.
1. Tunneling: It wraps (encapsulates) the data packets inside another packet header so that they can be routed privately over the public internet, acting like a private tunnel.
2. Encryption: It encrypts the payload of the packets. Even if an ISP or a hacker intercepts the data, they will only see unreadable ciphertext. Only the clinic's VPN gateway and the doctor's device have the decryption keys to read the sensitive medical records.

PastPaper.markingScheme

(a) [4 marks]
- 2 marks for Protocol: 1 mark for 'set of rules/standards' and 1 mark for explaining its purpose (e.g., enabling successful communication/compatibility between different systems).
- 2 marks for Data Packet: 1 mark for 'basic unit of data transmitted' and 1 mark for mentioning it contains both control information (headers/metadata) and payload (user data).

(b) [2 marks]
Award 1 mark for each valid benefit linked to the medical context (max 2 marks):
- Mobility / portability of tablets while treating patients.
- Cleanliness / safety (no physical cables to trip over or collect dust/bacteria in clinic rooms).

(c) [3 marks]
- 1 mark for stating MAC addresses are broadcast in plaintext / are easily intercepted.
- 1 mark for explaining MAC address spoofing (cloning an authorized MAC address onto an unauthorized device).
- 1 mark for concluding that it does not provide encryption, meaning data can still be intercepted even if access is restricted.

(d) [6 marks]
- 1 mark for stating that a VPN secures communication over an untrusted/public network (the internet).
- 2 marks for explaining Tunneling: encapsulation of original packets inside a new transit packet (1 mark), allowing safe passage through public routers (1 mark).
- 2 marks for explaining Encryption: converting patient data into ciphertext using cryptographic algorithms (1 mark), ensuring that intercepted data is unreadable without the correct decryption key (1 mark).
- 1 mark for linking to the context (protecting highly confidential patient health records / compliance).

Paper 2 Option D

Answer all questions from the chosen option (OOP).
3 PastPaper.question · 45 PastPaper.marks
PastPaper.question 1 · OOP class analysis, design, and coding
15 PastPaper.marks
A fitness tracker application contains a parent class Workout and a subclass CardioWorkout. The Workout class has attributes: duration (in minutes, integer) and difficulty (String). Part a: Define the term inheritance in relation to OOP. [2 marks] Part b: Outline the relationship between a User class and a Workout class if a User can perform multiple Workouts over time, referencing the concepts of aggregation or composition. [3 marks] Part c: The CardioWorkout class has an additional attribute averageHeartRate (integer). Write the complete Java code for the CardioWorkout class, including its constructor (which initialises duration, difficulty, and averageHeartRate) and a method calculateCalories() that returns a double. The calorie calculation is: duration multiplied by averageHeartRate multiplied by 0.12 if difficulty is 'HIGH', or multiplied by 0.08 otherwise. [6 marks] Part d: Explain how polymorphism allows a single method call to calculate total calories burned across an array of different Workout subclasses (e.g., CardioWorkout, StrengthWorkout) without knowing their specific types at compile time. [4 marks]
PastPaper.showAnswers

PastPaper.workedSolution

Part a: Inheritance is a mechanism where a new class (subclass) inherits attributes and methods from an existing class (superclass), promoting code reuse and establishing an 'is-a' relationship. Part b: The relationship is aggregation. A User has an association with a list of Workouts. It is aggregation rather than composition because a Workout object can exist independently of a specific User (e.g., in a workout history database or template library), and deleting the User does not necessarily destroy the workout definitions. Part c: public class CardioWorkout extends Workout { private int averageHeartRate; public CardioWorkout(int duration, String difficulty, int averageHeartRate) { super(duration, difficulty); this.averageHeartRate = averageHeartRate; } public double calculateCalories() { double factor = this.getDifficulty().equals("HIGH") ? 0.12 : 0.08; return this.getDuration() * this.averageHeartRate * factor; } } Part d: Polymorphism allows different subclasses to implement their own versions of calculateCalories(). If the parent class Workout defines a virtual/abstract calculateCalories() method, a loop can iterate through an array of Workout references and call calculateCalories() on each. The JVM dynamically binds the method call to the actual subclass implementation at runtime, calculating correct calories for each specific workout type dynamically.

PastPaper.markingScheme

Part a: [2 marks] 1 mark for mentioning subclass/superclass relationship or inheriting attributes/methods. 1 mark for mentioning code reusability or 'is-a' relationship. Part b: [3 marks] 1 mark for identifying aggregation. 1 mark for explaining that Workouts can exist independently of the User. 1 mark for explaining that destroying the User does not destroy the Workout objects. Part c: [6 marks] 1 mark for correct class header with extends. 1 mark for correct constructor signature and calling super() with correct arguments. 1 mark for initialising local attribute averageHeartRate. 1 mark for correct method header double calculateCalories(). 1 mark for correct conditional logic based on difficulty. 1 mark for correct calculation formula and returning double. Part d: [4 marks] 1 mark for defining polymorphism in context (many forms of a method). 1 mark for mentioning the parent class declaring the method. 1 mark for referencing dynamic/runtime binding. 1 mark for explaining how this avoids type checking (instanceof) during iteration.
PastPaper.question 2 · OOP class analysis, design, and coding
15 PastPaper.marks
A shipping yard logistics system manages cargo containers. A Cargo class has attributes: id (String), weight (double), and destination (String). Part a: Outline one advantage of using an array of Cargo objects over three parallel arrays (one for ID, one for weight, one for destination). [2 marks] Part b: Write the complete Java class definition for Cargo, including its private attributes, a constructor, and getter methods for all three attributes. [4 marks] Part c: The shipping yard is managed by a Yard class which contains an array of Cargo objects called storage (initially sized to 100 elements) and an integer variable cargoCount. Write a Java method findHeavyCargo(double minWeight) inside the Yard class that searches the storage array and returns a new array containing all Cargo objects whose weight exceeds minWeight. Assume the returned array should not contain null elements and should be sized exactly to fit the heavy cargo found. [7 marks] Part d: State two features of Object-Oriented Programming (excluding inheritance) that contribute to secure and modular code design. [2 marks]
PastPaper.showAnswers

PastPaper.workedSolution

Part a: Using an array of objects keeps related data encapsulated together in a single entity, which makes the code easier to maintain, less prone to index synchronization errors, and easier to pass as parameters. Part b: public class Cargo { private String id; private double weight; private String destination; public Cargo(String id, double weight, String destination) { this.id = id; this.weight = weight; this.destination = destination; } public String getId() { return this.id; } public double getWeight() { return this.weight; } public String getDestination() { return this.destination; } } Part c: public Cargo[] findHeavyCargo(double minWeight) { int count = 0; for (int i = 0; i < cargoCount; i++) { if (storage[i].getWeight() > minWeight) { count++; } } Cargo[] heavyCargo = new Cargo[count]; int index = 0; for (int i = 0; i < cargoCount; i++) { if (storage[i].getWeight() > minWeight) { heavyCargo[index] = storage[i]; index++; } } return heavyCargo; } Part d: Encapsulation (hiding implementation details and protecting data through access modifiers) and Abstraction (exposing only essential features while hiding background details).

PastPaper.markingScheme

Part a: [2 marks] 1 mark for explaining encapsulation of attributes into a single unit. 1 mark for explaining prevention of coordination errors (avoiding index mismatches across multiple arrays). Part b: [4 marks] 1 mark for declaring private attributes. 1 mark for correct constructor with parameter initialization using this. 1 mark for correct getters with appropriate return types. 1 mark for overall syntactical correctness. Part c: [7 marks] 1 mark for method signature public Cargo[] findHeavyCargo(double minWeight). 1 mark for iterating through active storage elements up to cargoCount (not storage.length). 1 mark for correctly checking weight condition (> minWeight). 1 mark for first counting the matching elements to determine array size. 1 mark for instantiating the destination array with correct size. 1 mark for secondary loop or index pointer to populate matching cargo elements. 1 mark for returning the new array. Part d: [2 marks] 1 mark for Encapsulation (with brief rationale). 1 mark for Abstraction (with brief rationale).
PastPaper.question 3 · OOP class analysis, design, and coding
15 PastPaper.marks
An electric vehicle charging hub contains a series of smart chargers. Each Charger has an ID (String), a status (String, e.g., 'FREE' or 'BUSY'), and a reference to the Vehicle object currently charging (which is null if the charger is free). Part a: Define the purpose of accessor (getter) and mutator (setter) methods in maintaining the principle of encapsulation. [3 marks] Part b: Explain the concept of a static variable in Java and explain why a static variable countOfActiveChargers would be useful in the Charger class. [3 marks] Part c: Write a Java method assignVehicleToCharger(Vehicle v, String chargerId) within a HubManager class. The HubManager class contains an array chargers of Charger objects. The method must search for a charger with the matching chargerId. If found and its status is 'FREE', it must set the charger's status to 'BUSY', assign the Vehicle v to it, and return true. If not found or not free, it must return false. [7 marks] Part d: Suggest one issue that can arise if the array chargers is full and a new Charger must be dynamically added during runtime, and state how a dynamic data structure can resolve this. [2 marks]
PastPaper.showAnswers

PastPaper.workedSolution

Part a: Accessor methods provide read-only access to private attributes without allowing direct modification. Mutator methods allow controlled modification of private attributes, enabling the class to validate input parameters before updating the state, thereby protecting class invariants and encapsulating the data. Part b: A static variable is shared among all instances of a class rather than being unique to each object. A static countOfActiveChargers variable allows the system to easily track the total number of currently busy chargers across the entire hub globally without needing to iterate through individual instances or maintain a separate manager variable. Part c: public boolean assignVehicleToCharger(Vehicle v, String chargerId) { for (int i = 0; i < chargers.length; i++) { if (chargers[i] != null && chargers[i].getId().equals(chargerId)) { if (chargers[i].getStatus().equals("FREE")) { chargers[i].setStatus("BUSY"); chargers[i].setVehicle(v); return true; } } } return false; } Part d: Fixed-size arrays cannot easily grow dynamically, requiring a costly process of allocating a new larger array and copying all elements across. A dynamic structure like an ArrayList or a LinkedList can grow dynamically as chargers are added without manual resizing or overhead issues.

PastPaper.markingScheme

Part a: [3 marks] 1 mark for accessor allowing safe read access. 1 mark for mutator allowing controlled updates/validation. 1 mark for mentioning protection of data/encapsulation. Part b: [3 marks] 1 mark for defining static (class-level variable shared by all instances). 1 mark for applying to countOfActiveChargers (global tracking of usage). 1 mark for explaining it avoids iterating through arrays or creating redundant external counters. Part c: [7 marks] 1 mark for correct method signature. 1 mark for loop traversing the chargers array safely checking for null elements. 1 mark for searching correct charger ID using .equals() (not ==). 1 mark for checking if charger status is 'FREE'. 1 mark for setting status to 'BUSY'. 1 mark for setting vehicle reference to v. 1 mark for returning true on success and false if not found or busy. Part d: [2 marks] 1 mark for identifying fixed-size limitation of arrays. 1 mark for suggesting a dynamic alternative (like ArrayList) that handles automatic resizing.

PastPaper.sampleCTATitle

PastPaper.sampleCTADescription

PastPaper.sampleStickyMessage

PastPaper.stickyCtaText