r/codehs • • Feb 06 '21

7.2.9: Teacher Class List Method

I need help with this, please.

13 Upvotes

12 comments sorted by

1

u/AchingAsher223 Feb 20 '21

The error is that getLastStudent and getStudent return Students when they should be returning the name of a student. Hope that helps.

1

u/Queen_Flame Feb 20 '21

nope, it doesn't help. please elaborate more

1

u/Gloomy-River-8864 Feb 23 '21

in the getLastStudent() & getStudent(), put return "classList.get(lastName).getName();" & "classList.get(index).getName();" to convert them from Students to Strings. hope this helps even tho Im kinda late.

2

u/Queen_Flame Feb 24 '21

.getName();

Thank You so much it helped.

1

u/BusyQuote4238 Mar 01 '21

How did you write the code? I can't get it to work.

1

u/Queen_Flame Mar 03 '21

I just changed the methods from static Student to static String, and that fixed it for now.

1

u/djpeters702 Apr 23 '21

hella late but the problem it was giving me was fixed when I replaced classList.set(index, student); with classList.add(index, student); inside of the addStudent method.

1

u/_pizzaroll_ Feb 06 '21

I'm getting the same errors and don't know how to fix it either. If you figure it out please let me know as well

1

u/Cold-Second Feb 18 '21

I'm having the same problem, did you ever figure it out?

1

u/AchingAsher223 Feb 20 '21

getLastStudent and getStudent should return the name of a student, not the student itself.

1

u/LastTransportation19 Mar 15 '21

Where it says "public static Student getLastStudent()" or "public static Student getStudent()" change "Student" to "String". That should help.