Question 2991
Multiple choice
Unit 4: Data Collections
Consider the following Student class.
public class Student {
private String name;
private int grade;
public Student(String name, int grade) { this.name = name; this.grade = grade; }
public String getName() { return name; }
public int getGrade() { return grade; }
} A text file contains:Alice,90Bob,85What 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();
System.out.println(list.get(1).getName());
Pick an answer, then check it. The solution opens in a window.
BCorrect answer
Answer images

