Write a method setRating that reads a rating from the keyboard, insisting that the rating supplied by the user be valid.
rating should be 1 to 5;
public void setRating(){
System.out.println("enter rating ");
int myRating = keyboard.nextInt();
}
is this correct?
or need to include like this
public void setRating(){
System.out.println("enter rating ");
int myRating = keyboard.nextInt();
while((rating >= 1) && (rating <= 5))
{
System.out.println("Error - rating not in range");
System.out.println("enter rating again ");
myRating = keyboard.nextInt();
}
}