Question 3011
Student with constructor Student(String name, int grade) and methods getName() returning the name and getGrade() returning the grade. A text file contains:Alice,80Bob,90Carol,70Dave,85Eve,95What 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();
int sum = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getGrade() >= 85) {
sum = sum + list.get(i).getGrade();
}
}
System.out.println(sum);Answer images

