Exam Free Response 1 Practice: RosterTools.initials 🌶️🌶️
This is practice in the shape of AP Exam Free Response Question 1 (Methods and Control Structures): for a partially-written class, write one of its methods.
Below is the start of a RosterTools class that will eventually hold a few helper methods for building roster reports. Write the initials method: given a Student whose name is in "First Last" format, return a two-character String made of the first letter of the first name and the first letter of the last name. For example, if a Student's name is "Ada Lovelace", initials should return "AL". You may assume every name has exactly one space, separating a first and a last name.
Reference: Student — the methods you can call
class Student
A student record: a name, a score and an attendance percentage. A Student never changes once it is made. You do not write this class; make a record with new Student(name, score, attendance) and call its methods.
Student s = new Student("Ana", 92, 97);
s.getName() // "Ana"
s.getLetterGrade() // "A"
s.isPassing() // true
s.toString() // "Ana: 92 (A), 97% attendance"
s.equals(new Student("Ana", 92, 97)) // true
| Method | What it does |
|---|---|
Student(String name, int score, int attendance) | Makes a student record.
|
String getName() | The student's name. Returns the name |
int getScore() | The student's score. Returns the score |
int getAttendance() | The attendance percentage. Returns the attendance percentage |
boolean isPassing() | Whether the student is passing. Returns true if the score is 60 or above |
String getLetterGrade() | The letter grade for the score, with the usual 90, 80, 70 and 60 cutoffs. Returns "A", "B", "C", "D" or "F" |
boolean equals(Object o) | Whether another object is a Student with the same name, score AND attendance.
Returns true if all three match; false otherwise |
String toString() | The student as text, for example "Ana: 92 (A), 97% attendance". It is called for you by Returns the student as text |