Write an application that allows a user to enter any number of student test scor
ID: 3877316 • Letter: W
Question
Write an application that allows a user to enter any number of student test scores using that number to create a loop until the user enters all the scores, DO NOT USE "QUIT" to stop entering scores. If the score entered is less than 0 or more than 100, display an appropriate message and do not use the score. After all the scores have been entered, display the number of scores entered, the highest score, the lowest score, and the arithmetic average. Save the file as TestScoreStatistics.java.
//DO NOT USE "QUIT" to stop entering scores.
//Instead, ask the user how many grades they are going to enter. Use this number to create a loop.
import java.util.*;
public class TestScoreStatistics
{
public static void main (String args[])
{
int score;
int total = 0;
int count = 0;
int highest;
int lowest;
final int QUIT = 999;
final int MIN = 0;
final int MAX = 100;
Scanner input = new Scanner(System.in);
System.out.print("How many scores would you like to enter >> ");
enterCount = input.nextInt();
System.out.print("Enter a score >> ");
score = input.nextInt();
//Create a while statement that will loop for the amount entered
while( )
{
}
System.out.print("Enter another score >> ");
score = input.nextInt();
}
System.out.println(count + " scores were entered");
System.out.println("Highest was " + highest);
System.out.println("Lowest was " + lowest);
System.out.println("Average was " + (total * 1.0 / count));
}
}
//Sample output
How many scores would you like to enter? >> 4
Enter a score >> 90
Enter another score >> 95
Enter another score >> 78
Enter another score >> 50
4 scores were entered
Highest was 95
Lowest was 50
Average was 78.25
Explanation / Answer
TestScoresStatistics.java
import java.util.Scanner;
public class TestScoresStatistics {
public static void main(String[] args) {
int score;
int total = 0;
int count = 0,entercount;
int highest;
int lowest;
final int QUIT = 999;
final int MIN = 0;
final int MAX = 100;
Scanner input = new Scanner(System.in);
System.out.print("How many scores would you like to enter >> ");
entercount = input.nextInt();
System.out.print("Enter a score >> ");
score = input.nextInt();
highest=score;
lowest=score;
/* This while loop continues to execute
* until the user enters a 999 as input
*/
while(entercount>0)
{
if(score<0 || score>100)
{
System.out.println("Invalid.Must be between 0-100");
}
else
{
entercount--;
count++;
//calculating the total
total+=score;
//finding the lowest score
if(lowest>score)
lowest=score;
//finding the highest score
if(highest<score)
highest=score;
}
if(entercount>0)
{
//Getting the input entered by the user
System.out.print("Enter another score >>");
score=input.nextInt();
}
}
//Displaying the result
System.out.println("The number of scores entered :"+count);
System.out.println("The highest score :"+highest);
System.out.println("The lowest score:"+lowest);
System.out.println("Average was " + (total * 1.0 / count));
}
}
__________________
Output:
How many scores would you like to enter >> 4
Enter a score >> 90
Enter another score >>95
Enter another score >>78
Enter another score >>50
The number of scores entered :4
The highest score :95
The lowest score:50
Average was 78.25
_______________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.