MovieGuide.Java // MovieGuide.java - This program allows each theater patron to
ID: 3814848 • Letter: M
Question
MovieGuide.Java
// MovieGuide.java - This program allows each theater patron to enter a value from 0 to 4
// indicating the number of stars that the patron awards to the Guide's featured movie of the
// week. The program executes continuously until the theater manager enters a negative number to
// quit. At the end of the program, the average star rating for the movie is displayed.
import javax.swing.JOptionPane;
public class MovieGuide
{
public static void main(String args[])
{
// Declare and initialize variables.
double numStars; // star rating.
String numStarsString; // string version of star rating
double averageStars; // average star rating.
double totalStars = 0; // total of star ratings.
int numPatrons = 0; // keep track of number of patrons
// This is the work done in the housekeeping() method
// Get input.
// This is the work done in the detailLoop() method
// Convert to double.
// Write while loop here
// This is the work done in the endOfJob() method
// Calculate average star rating
System.out.println("Average Star Value: " + averageStars);
System.exit(0);
} // End of main() method.
} // End of MovieGuide class.
Using a Sentinel Value to Control a while Loop In this lab, you write a while loop that uses a sentinel value to control a loop in a Java program provided with the data files for this book. You also write the statements that make up the body of the loop. The source code file already contains the necessary variable declarations and output statements. You designed this program for the Hollywood Movie Rating Guide in Chapter 5 Exercise 15, in Programming Logic and Design. Each theater patron enters a value from 0 to 4 indicating the number of stars that the patron awards to the Guide's featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. At the end of the program, you should display the average star rating for the movie. 1. Open the source code file named Movie Guide.java using Notepad or the text editor of your choice 2. Write the while loop using a sentinel value to control the loop, and also write the statements that make up the body of the loop. 3. Save this source code file in a directory of your choice, and thin make that directory your working directory. 4. Compile the source code file, movieGuide.java 5. Execute the program. Input the following as star ratings 0 4 1 1 1 6. Record the average star rating for the movieExplanation / Answer
package movieguide;
// MovieGuide.java - This program allows each theater patron to enter a value from 0 to 4
// indicating the number of stars that the patron awards to the Guide's featured movie of the
// week. The program executes continuously until the theater manager enters a negative number to
// quit. At the end of the program, the average star rating for the movie is displayed.
import javax.swing.JOptionPane;
public class MovieGuide
{
public static String housekeeping(){
String inputValue = JOptionPane.showInputDialog("Enter the number");
return inputValue;
}
public static double detailLoop(String convertValue){
double convertedValue = Double.parseDouble(convertValue);
return convertedValue;
}
public static double endOfJob(double sum, int count){
return (double)sum/count;
}
public static void main(String args[])
{
// Declare and initialize variables.
double numStars; // star rating.
String numStarsString; // string version of star rating
double averageStars = 0; // average star rating.
double totalStars = 0; // total of star ratings.
int numPatrons = 0; // keep track of number of patrons
// This is the work done in the housekeeping() method
// Get input.
numStarsString = housekeeping();
numStars = detailLoop(numStarsString);
// This is the work done in the detailLoop() method
// Convert to double.
while(numStars > -1){
totalStars = totalStars+ numStars;
numPatrons = numPatrons +1;
numStarsString = housekeeping();
numStars = detailLoop(numStarsString);
}
// Write while loop here
averageStars = endOfJob(totalStars,numPatrons );
// This is the work done in the endOfJob() method
// Calculate average star rating
System.out.println("Average Star Value: " + averageStars);
System.exit(0);
} // End of main() method.
} // End of MovieGuide class.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.