Computer Science · Oct / Nov 2024 · Paper 2 HL · Question 14
IBCS
As printed in the paper
The question as text
14. A school requires all its 250 students to go on a four-day field trip. The school offers 16 different trips. A maximum of 25 places are available on each trip. Each student submits a request form with their top 10 trip preferences. The trip coordinator assigns each student a place on a trip based on their preferences and the availability of places on that trip. A trip will not run if fewer than 10 places are filled after all the student requests have been processed. For example, if 9 or fewer students have requested the second trip, it will not run. The Trip class keeps the details of each trip. Part of the code for this class is shown below: public class Trip { private int tripNumber; // id of the trip private String tripTitle; // trip Name private String tripDesc; // trip description private int placesFilled; // number of places filled private boolean isRunning; // status of the trip private ArrayList <String> tList = new ArrayList<String>(); public Trip(int tripNumber, String tripTitle, String tripDesc) { this.tripNumber = tripNumber; this.tripTitle = tripTitle; this.tripDesc = tripDesc; this.placesFilled = 0; this.isRunning = false; } public String getTripTitle() {return tripTitle;} public ArrayList<String> getList() {return tList;} public int getPlacesFilled() {return placesFilled;} public boolean isRunning() {return isRunning;} public void setTripTitle(String tripTitle) { this.tripTitle = tripTitle;} public void updatePlacesFilled() { this.placesFilled++; // code missing to change the trip running status } public void addStudentToTripList(Student s){ tList.add(s.getName());} // all accessor and mutator methods are present but not shown }// end of Trip class (Option D continues on the following page) (Option D, question 14 continued) The Student class keeps the details of a student. Part of the code for this class is shown below: public class Student { private String sId; // unique id of the student private String sName; // name of the student private int sGrade; // grade level of the student private String tripAssigned; // trip Title assigned to the student public int[] sPreferenceList = new int[10]; // preferred trip numbers public Student(String sID, String sName, int sGrade, int[]sPreferenceList) { this.sId = sId; this.sName = sName; this.sGrade = sGrade; this.sPreferenceList = sPreferenceList; this.tripAssigned = "zzz"; } public void setTripAssigned(String tripAssigned) { this.tripAssigned = tripAssigned;} public String getName() {return sName;} public String getTripAssigned() {return tripAssigned;} // all accessor and mutator methods are present but not shown }// end of Student class (Option D continues on the following page) (Option D, question 14 continued) The TripAllocator class has the main method and other methods to assign trips and generate the information required. public class TripAllocator { private Trip[] allTrips = new Trip[16]; // trips are stored in the ascending order of the trip number private Student[] allStudents = new Student[250]; public void assignTrip(Student s) // assigns a trip to a student {// code missing} public void displayPlacesLeft() {// code missing} }
Read automatically from the paper; the printed page above is exact.
Show the answer and mark scheme
14(a)[1]
14(b)[2]
14(c)[2]
14(d)[2]
14(e)[6]
14(f)[2]
Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.

