Note AcademyNote Academy

Computer Science · Oct / Nov 2020 · Paper 2 SL · Question 10

Adapt for 2027Static variables, the this keyword and creating objects in Java are in B3.1; the class relationship part uses the Higher Level aggregation outcome. Includes Higher Level only content, which Standard Level students do not study.

IBCS

As printed in the paper

The question as text

10. A company provides car parking services in large cities and needs a computer system to keep track of the number of vehicles using its parking areas. When a vehicle arrives, its registration plate is recorded on the system and it is allocated a number that identifies where it should park. When the vehicle leaves, that space is made available for other vehicles to use. Vehicles are identified by their unique registration plate, which is an alphanumeric code of eight characters (eg X1234567). This is clearly displayed on the vehicle. A programmer created the classes ParkingArea and Vehicle to model the above situation. public class ParkingArea { private Vehicle vehicles[]; private String name; ParkingArea(String name, int capacity) { this.name = name; if (capacity > 300) capacity = 300; this.vehicles = new Vehicle[capacity]; } String getName() { return name; } public int getCapacity() { return vehicles.length; } public int findVehicle(String reg) { //find where the vehicle is located in the array and //return the index not yet written } } (Option D continues on the following page) (Option D, question 10 continued) public class Vehicle { private String registration; private byte colour; private boolean broken; public final static byte BLACK=1; public final static byte WHITE=2; public final static byte BLUE=3; public final static byte RED=4; public final static byte GREEN=5; private final static double ADMIN_FEE = 3; public Vehicle() {} public Vehicle(String registration) { this.registration = registration; } public Vehicle(String registration, byte colour) { this.registration = registration; this.colour=colour; } public void setBroken(boolean broken) { this.broken=broken; } public void setColour(byte colour) { this.colour=colour; } public boolean getBroken() { return broken; } public String getRegistration() { return registration; } public double pay(int hours) { // code to return admin fee - only if applicable } }

Read automatically from the paper; the printed page above is exact.

Show the answer and mark scheme
  • 10(a)[2]

  • 10(b)[3]

  • 10(c)[2]

  • 10(d)(i)[2]

  • 10(d)(ii)[2]

Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.