Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solve this Java problem: develop a program containing a while-loop. Prompt a user for quiz scores. The loop will continue prompting for numbers until the
Solve this Java problem: develop a program containing a while-loop. Prompt a user for quiz scores. The loop will continue prompting for numbers until the user types the word "stop". The loop should: a. Perform a running sum of the input values. b. Keep track of the minimum. c. Keep track of the maximum. d. Count the number of values entered by the users. e. Compute the average from the running-sum total and the count. f. Neatly display all the above information using the printf() method. Here is my code:
import java.util.Scanner; public class QuizScores public static void main(String[] args) { //Define a scanner object for input Scanner sc = new Scanner(System.in); //Declare and initialize all required variables int score = 0; int count = 0; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int total = 0; float avg = 0; //Start a infinite while loop while(true) { //Take input from user String s = sc.next(); //Compare the input with stop and exit. if matches then break the loop if (s.equals("stop") || s.equals("exit")){ //Output all the desired information to console System.out.printf("Number of values entered is : %d ", count); System.out.printf("Minimum of all entered values is %d ", min); System.out.printf("Maximum of all entered values is %d ", max); System.out.printf("Sum of all entered values is : %d ", total); System.out.printf("Average of all entered values is %.1f ", avg); return; } else { //Parse the string to integer score = Integer.parseInt(s); //Update the value of total total = total + score; //Update the variable count count++; avg = total/count; //Check if the new score is less than minimum if (score min) { } min = score; ////Check if the new score is greater than maximum if(score > max) { max = score; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Algorithm Initialize variables total sum of scores average average score num current input score min minimum score max maximum score count number of scores entered and str string to read input Prompt ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started