You will write a program that computes quiz score statistics. Ask a student to e
ID: 3679627 • Letter: Y
Question
You will write a program that computes quiz score statistics. Ask a student to enter their quiz scores, one score at a time. Tell them to just hit the ENTER key instead of typing in a score when they are finished. After you have all the quiz scores, display all the quiz scores. You are then required to compute the average quiz score. You should also find the minimum and maximum quiz scores. You should also tell the user how many quizzes they took. Your program should look like this, input may vary. Please enter quiz scores one at a time. Press ENTER instead of typing in a score when you are finished. quiz 1: 14 quiz 2: 8 quiz 3: 10 quiz 4: 15 quiz 5: Your quiz scores are: quiz 1: 14 quiz 2: 8 quiz 3: 10 quiz 4: 15 number of quizzes: 4 min score: 8 max score: 15 avg score: 11.75
Explanation / Answer
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class HelloWorld{
public static void main(String []args){
HelloWorld test=new HelloWorld();
test.readScores();
}
public void readScores()
{
int quiz[]=new int[10];
int max=0,min=999999,size=1;
BufferedReader br = null;
boolean flag=true;
try
{
br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter scores");
while(flag)
{
System.out.print("Quiz "+size +": ");
String tmp=br.readLine();
if(tmp.equals(""))
{
flag=false;
break;
}
quiz[size]=Integer.parseInt(tmp);
if(quiz[size]>max)
max=quiz[size];
if(quiz[size]<min)
min=quiz[size];
size++;
}
}
catch(IOException nfe){
System.err.println("Invalid Format!");
}
System.out.println("Your scores are");
for(int i=1;i<size;i++)
System.out.println(quiz[i]);
System.out.println("Max score:"+max);
System.out.println("Min score:"+min);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.