lundi 2 novembre 2015

Eclipse won't allow me to return a String and insists on return null, what can I change please?

Need to translate a star cartoon into a program. For the numeric ratings given i.e. 1.0, 3.5 etc it should return a textual interpretation as in "OK" or "excellent" and otherwise "not rated". Eclipse won't let me compile without asking for return null and I am stuck, Thank you for help!

public class StarRating { 

public static String interpret (double rating) {
         if ( rating <= 3.5 )  {
            System.out.println ("crap"); 
        }
        else if (rating == 4.0) {
            System.out.println   ("OK");
        }
        else if (rating == 4.5){
        System.out.println ("excellent");
        }
        else if (rating == 5.0){
        System.out.println ("[has only one review]");
        }
        else 
            System.out.println("not rated");
         return null; //eclipse won't compile without return null
}
}

Aucun commentaire:

Enregistrer un commentaire