Write a BlueJ project consisting in a class named Lecture whose goal is to store a list of the student names (of type String) attending it. In addition to declaring and initializing the necessary fields, the class has to implement: • A method boolean addStudent(String name) that adds a name to the (internal) list and returns an appropriate value (see Hint): the returned boolean value must be the same returned by the method add of the “internal list”. • A method int getHomonymNumber(String name) that returns the number of students that have the indicated name. • A method void printCSList() that prints the list of student names, in one single line and separated by a comma. For example: Goofy, Donald, Mickey Notice that you may not print a comma after the last name! • A method boolean swap(int index1, int index2) that swaps 2 students names in the list and returns true if the operation is successful. • A method void testIt() that adds at least 4 students (at least two with the same name), prints the list on a single line, swaps 2 students, prints again the list and finally prints the number of students with the same name (for a name you inserted twice in the list
Write a BlueJ project consisting in a class named Lecture whose goal is to store a list of the student names (of type
String) attending it. In addition to declaring and initializing the necessary fields, the class has to implement:
• A method boolean addStudent(String name) that adds a name to the (internal) list and returns an appropriate
value (see Hint): the returned boolean value must be the same returned by the method add of the “internal list”.
• A method int getHomonymNumber(String name) that returns the number of students that have the indicated
name.
• A method void printCSList() that prints the list of student names, in one single line and separated by a
comma. For example:
Goofy, Donald, Mickey
Notice that you may not print a comma after the last name!
• A method boolean swap(int index1, int index2) that swaps 2 students names in the list and returns true
if the operation is successful.
• A method void testIt() that adds at least 4 students (at least two with the same name), prints the list on a
single line, swaps 2 students, prints again the list and finally prints the number of students with the same name
(for a name you inserted twice in the list)
Step by step
Solved in 2 steps with 1 images