Question 2721
Student with constructor Student(String name, int grade) and methods getName() returning the name and getGrade() returning the grade. A text file contains:Alice,95Bob,60Carol,82Dave,45Eve,90What is printed?
ArrayList<Student> list = new ArrayList<Student>();
while (sc.hasNext()) {
String[] parts = sc.nextLine().split(",");
list.add(new Student(parts[0], Integer.parseInt(parts[1])));
}
sc.close();
ArrayList<Student> honor = new ArrayList<Student>();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getGrade() >= 80) {
honor.add(list.get(i));
}
}
System.out.println(honor.size());Answer images

