I'm trying to create a method where it outputs a certain number of stars based on the rating of a movie. We are supposed to use toString, and I'm getting really confused about how this works. No tests seem to work, as you cannot add static to the method but it can't seem to be without it in the test. I'm not really sure if I'm supposed to create some sort of object, or how I go about calling the result I want in assertEquals within the test. Help would be very much appreciated! At the beginning of the class I wrote: public static String result; but I'm not really sure that's right either.
public String toString() {
if (Rating.votes > 1)
{
if (computeScore() > 1 && computeScore() < 2)
{
result = "*";
}
else if (computeScore() > 2 && computeScore() < 3)
{
result = "**";
}
else if (computeScore() > 3)
{
result = "***";
}
else if (computeScore() < 1)
{
result = " ";
}
}
return result;
}
Aucun commentaire:
Enregistrer un commentaire