This is how I am calling the method in MovieRatingApp class.
movie1.getRatingDesc()
This is the getRatingDesc() method in the Movie class.
public String getRatingDesc(int reviewNum)
{
String s = "";
switch (reviewNum)
{
case 1:
s = "Terrible";
break;
case 2:
s = "Bad";
break;
case 3:
s = "Ok";
break;
case 4:
s = "Good";
break;
case 5:
s = "Great";
break;
}
return s;
}
Every time I try to call the method I get an error: method getRatingDesc() from class Movie cannot be applied to given types.
When I change how I call my method to, movie1.getRatingDesc(int numReview) I get a different error. But what I really want to do is return the value of the variable "s" which describes the rating.
Just pass in the variable in your call.
int numReview; //declare numReview.
Scanner sc = new Scanner(System.in); //Assuming you're going to have the user type it in.
numReview = sc.nextInt(); //Accept next integer from console, store in variable.
System.out.println(movie1.getRatingDesc(numReview)); //Call it, print result.
Note that error handling is omitted. If somebody tries to enter text or a number that is unexpected, you'll need to be responsible for how that's treated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.