Class StudentRoster
java.lang.Object
solution.StudentRoster
Class for managing student names and ids.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new StudentRoster with empty ArrayLists for ids and names. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStudent(String name, int id) Adds a student's name and id to the ArrayLists for names and ids.voidchangeName(Integer id, String newName) Changes the name of the student with the given id.getStudentID(String name) Returns an Arraylist of ids for students with the passed-in name.Returns the student name that corresponds to the passed-in id.booleanhasStudent(Integer id) Returns true if there is a student with the passed-in id.booleanhasStudent(String name) Returns true if there is a student with the passed-in name.voidremoveStudent(Integer id) Removes the student with the passed-in id from the Arraylist of ids and the corresponding name from the Arraylist of names.voidremoveStudent(String name) Removes all students with the passed-in name from the Arraylist of names and their corresponding ids from the Arraylist of ids.toString()Returns a String that has the id and name of each student on a separate line.
-
Constructor Details
-
StudentRoster
public StudentRoster()Creates a new StudentRoster with empty ArrayLists for ids and names.
-
-
Method Details
-
addStudent
Adds a student's name and id to the ArrayLists for names and ids. The id is inserted into the Arraylist of ids such that the Arraylist is sorted in ascending order. The name should be inserted into the Arraylist of names so it has the same index as the id. If the passed-in id is already in the Arraylist of ids nothing happens. You are not allowed to, and don't need to, use any built-in sort methods.- Parameters:
name- Name of the student.id- ID of the student.
-
hasStudent
Returns true if there is a student with the passed-in id.- Parameters:
id- ID to look up in the Arraylist of ids.- Returns:
- True if id is in the Arraylist of ids, False otherwise.
-
hasStudent
Returns true if there is a student with the passed-in name.- Parameters:
name- Name to look up in the Arraylist of names.- Returns:
- True if name is in the Arraylist of names, False otherwise.
-
removeStudent
Removes all students with the passed-in name from the Arraylist of names and their corresponding ids from the Arraylist of ids. If the student name is not in names, nothing happens.- Parameters:
name- Name of student(s) to remove.
-
removeStudent
Removes the student with the passed-in id from the Arraylist of ids and the corresponding name from the Arraylist of names. If the student name is not in names, nothing happens.- Parameters:
id- ID of the student to remove.
-
getStudentID
Returns an Arraylist of ids for students with the passed-in name. If there are no students with the passed-in name, returns an empty Arraylist.- Parameters:
name- Name of student(s) whose ids we want.- Returns:
- ArrayList of ids for the student name passed-in.
-
getStudentName
-
changeName
-
toString
-