import java.util.ArrayList;
import java.util.Collections;
public class TeamApp {
private static final double MIN_GPA = 3.67; // required by the assignment
public static void main(String[] args) {
// Scenario A: has candidates
runScenario(buildScenarioA());
System.out.println(); // blank line between the two scenarios
// Scenario B: no candidate
runScenario(buildScenarioB());
}
private static void runScenario(Team<Student> studentList) {
// 1) Applicants
System.out.println("The following students want to join the competition team:");
if (studentList.hasNoMember()) {
System.out.println("No student/candidate in the list.");
} else {
System.out.print(studentList); // Team#toString prints one per line
}
System.out.println();
// 2) Total number (own section, like the sample)
System.out.println("Total number of students = " + studentList.getNumberOfMembers());
System.out.println();
// 3) Not fulfilling the requirement
System.out.println("Students who do not fulfill cumulative GPA requirement ("
+ String.format("%.2f", MIN_GPA) + "):");
Team<Student> candidates = new Team<>();
for (Student s : studentList.toArrayListCopy()) {
Student standard = new Student("standard", MIN_GPA);
if (s.compareTo(standard) >= 0) {
candidates.addToTeam(s);
} else {
System.out.println("Remove: " + s);
}
}
System.out.println();
// 4) Candidates who HAVE fulfilled the requirement
System.out.println("Candidates who have fulfilled cumulative GPA requirement ("
+ String.format("%.2f", MIN_GPA) + "):");
if (candidates.hasNoMember()) {
System.out.println("No candidate has been selected!");
} else {
System.out.print(candidates);
}
System.out.println();
// 5) Remove the last submitted candidate
System.out.println("The following candidate who submitted the application last has been removed from the list:");
Student removed = candidates.removeFromTeam(); // remove last (stack behavior)
if (removed == null) {
System.out.println("No candidate in the list.");
} else {
System.out.println("Remove: " + removed);
}
System.out.println();
// 6) Sort candidates in DESC order and print
System.out.println("The candidates are sorted in a descending order based on their cumulative GPA :");
if (candidates.hasNoMember()) {
System.out.println("No candidate in the list.");
} else {
ArrayList<Student> finalList = candidates.toArrayListCopy();
Collections.sort(finalList, Collections.reverseOrder()); // descending by GPA
for (Student s : finalList) {
System.out.println(s);
}
}
}
// ---------- Data sets ----------
// Scenario A: has candidates (custom data; not copying the sample numbers)
private static Team<Student> buildScenarioA() {
Team<Student> t = new Team<>();
t.addToTeam(new Student("Alice", 3.55));
t.addToTeam(new Student("Brian", 3.74)); // candidate
t.addToTeam(new Student("Chloe", 3.28));
t.addToTeam(new Student("Diego", 3.10));
t.addToTeam(new Student("Eva", 3.92)); // candidate
t.addToTeam(new Student("Frank", 3.45));
t.addToTeam(new Student("Grace", 3.88)); // candidate
t.addToTeam(new Student("Henry", 3.67)); // candidate (edge meets spec)
return t;
}
// Scenario B: no candidate (all below 3.67)
private static Team<Student> buildScenarioB() {
Team<Student> t = new Team<>();
t.addToTeam(new Student("Iris", 3.21));
t.addToTeam(new Student("Jason", 3.50));
t.addToTeam(new Student("Kara", 3.33));
return t;
}
}