import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; public class Student { public static final int NPREF = 5; private School[] preferences = new School[NPREF]; public Student(School... preferences) { for (int i = 0; i < NPREF && i < preferences.length; i++) { this.preferences[i] = preferences[i]; } } public Student(List preferences) { for (int i = 0; i < NPREF && i < preferences.size(); i++) { this.preferences[i] = preferences.get(i); } } public int getScore(School school) { for (int i = 0; i < NPREF; i++) { if (preferences[i] == school) return 1 << (NPREF - i - 1); } return 0; } public School[] getPreferences() { return Arrays.copyOf(preferences, NPREF); } public School getPreference(int i) { return preferences[i]; } public String toString() { return Arrays.stream(preferences) .filter(Objects::nonNull) .mapToInt(School::getID) .mapToObj(Integer::toString) .collect(Collectors.joining(">")); } }