Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming 3. Design a program for the Hollywood Movie Rating Guide, in wh

ID: 3589923 • Letter: J

Question

Java Programming 3. Design a program for the Hollywood Movie Rating Guide, in which users continuously enter a value from 0 to 4 that indicates the number of stars they are awarding to the Guide’s featured movie of the week. The program executes continuously until a user enters a negative number to quit. If a user enters a star value that does not fall in the correct range, reprompt the user continuously until a correct value is entered. At the end of the program, display the average star rating for the movie.

Explanation / Answer

import java.util.Scanner;

public class MovieRatting {

public static void main(String[] args) {

// TODO Auto-generated method stub

int numberOfMovies=0;

int rating=0;

int ratingSum=0;

boolean flag=false;

while(rating>=0)

{

System.out.println("Enter Movie Ratings, enter negative number to quit: ");

Scanner sc=new Scanner(System.in);

rating=sc.nextInt();

if(rating<0)

{

break;

}

else if(rating>4)

{

do {

System.out.println("please enter the rating in the range of 0-4");

rating=sc.nextInt();

}while(rating>4);

if(rating<0)

{

flag=true;

break;

}

else

{

ratingSum=ratingSum+rating;

numberOfMovies++;

}

}

else

{

numberOfMovies++;

ratingSum=ratingSum+rating;

}

}

if(numberOfMovies==0)

{

System.out.println("Avg Rating of the movies is: "+numberOfMovies);

}

else

{

double avgRating=ratingSum/numberOfMovies;

System.out.println("Avg rating of the movies is "+avgRating);

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote