Unit 7, Lesson 2, Level 6, (a) School Club - Incorrect Test?

Students and I came up with the same code as the Example solution, but cannot pass the Test.

I tested the Example solution1 code and it could not pass the Test either.

Please advise - thanks!

1 Like

@williamsj1 - Thanks for posting about this issue. Could you please post a image of the code you are using?
Thanks,
Sylvia

Hi,
This is CSA('23-'24)
The Example Solution1 code is as follows
/* ----------------------------------- TO DO -----------------------------------

  • :white_check_mark: Write the addServiceHours() method to add a specified number of hours to
  • a club member. The method should have a parameter for a ClubMember object and
  • the number of hours to add, and it should add the hours to the ClubMember
  • object’s current service hours.

*/
public void addServiceHours(ClubMember member, int numHours) {
member.setServiceHours(member.getServiceHours() + numHours);
}

/*

  • Returns a String containing information about the club sponsor
    */
    public String toString() {
    String text = "Club Sponsor: " + sponsor + “\n”;

for (ClubMember student : members) {
text = text + student + “\n”;
}

return text;
}

The Example Solution1 Runner code is:
/* ----------------------------------- TO DO -----------------------------------

  • :white_check_mark: Call the addServiceHours() method, then print the updated ClubSponsor object.

*/

// Calls the addServiceHours
sponsor.addServiceHours(naomi, 7);
sponsor.addServiceHours(ariana, 4);

// Prints the updated ClubSponsor object
System.out.println(sponsor);

}
The Test results are:
[JAVALAB] Connecting…
[JAVALAB] Compiling…
[JAVALAB] Compilation successful.
[JAVALAB] Running level tests…

:heavy_check_mark: ClubSponsor.java Test > addServiceHours() has a parameter for a ClubMember object => SUCCEEDED
:heavy_check_mark: ClubSponsor.java Test > addServiceHours() has a parameter for the number of hours to add => SUCCEEDED
:heavy_check_mark: ClubSponsor.java Test > addServiceHours() has a void return type => SUCCEEDED
:heavy_multiplication_x: ClubSponsor.java Test > addServiceHours() adds the specified number of hours to the ClubMember object’s service hours => FAILED
Call the getServiceHours() method in the ClubMember class to get the current service hours. Add the
parameter for the number of hours to the current service hours and update the ClubMember object’s
serviceHours instance variable with the new value using the setServiceHours() method.
==> expected: <24> but was: <15> (ClubSponsorTest.java:90)

[JAVALAB] Program completed.

Hope that helps!
Jayne

@williamsj1 - Thank you for the information. I am also seeing the same failed test. I will pass this on to the curriculum team. We appreciate you posting this bug and any others you may encounter. I will post any updates to this thread.
Sylvia

3 Likes