Student: Quick Reference 🌶️
Some problems ask your method to accept a Student parameter, or an ArrayList<Student> — a record of one student's name, score, and attendance. You never reach into a Student's fields directly; call its methods instead.
You never build a
An
Student's letter grade or pass/fail status yourself — construct it with a name, score, and attendance, then call its methods.| Method | What it does |
|---|---|
new Student(name, score, attendance) | Creates a record: a String name, an int score, an int attendance percentage |
s.getName() | Returns the name, as a String |
s.getScore() | Returns the score, as an int |
s.getAttendance() | Returns the attendance percentage, as an int |
s.isPassing() | Returns true if the score is 60 or above |
s.getLetterGrade() | Returns the letter grade for the score ('A'–'F', the usual 90/80/70/60 cutoffs), as a char |
s.equals(other) | Returns true if both students have the same name, score, AND attendance |
s.toString() | Returns the student as text — called automatically by System.out.println(s) |
Student s = new Student("Ada", 95, 92);boolean passing = s.isPassing(); // truechar grade = s.getLetterGrade(); // 'A'System.out.println(s); // prints: Ada: 95 (A), 92% attendance
An
ArrayList<Student> works exactly like an ArrayList<Integer> or ArrayList<String> you've already used — students.get(i) gives you one Student, and students.size() gives you how many there are. The only difference is what you do once you have one: call .getScore(), .getAttendance(), or any of its other methods, the same as any other Student.