← all problems

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
MethodWhat it does
Student(String name, int score, int attendance)

Makes a student record.

  • name – the student's name
  • score – the score, as an int
  • attendance – the attendance percentage, as an int
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.

  • o – the object to compare with

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 System.out.println(s).

Returns the student as text

RosterTools.java — the class below is already written; you're only completing the method in the editable box.

class RosterTools {
    
    // ---- write your method below ----
}