Write a java application that uses an integer array to get a series of test scor
ID: 3772602 • Letter: W
Question
Write a java application that uses an integer array to get a series of test scores, compute the average and output the scores in tabular form and the class averages rounded to 2 decimal places.
Class report
Test# Test score
1 92
2 85
3 78
4 90
5 86
6 93
7 88
Class average
87.43
My program doesnt run correctly PLEASE HELP
import java.util.Scanner;
public class testScore
{
public static void main(String [] args)
{
//local constant
int MAXSIZE=25;
int numTest = -1;
int total = 0;
//local variables
float average;
int testScores[] = new int [MAXSIZE];
Scanner in= new Scanner(System.in);
//***************************************************************************************//
do
{
//Increment number of test
numTest++;
//Ask user to enter test score
System.out.println("Enter Test score of Test: " + (numTest+1) + " < -1 to exit > ");
total= total + testScores[numTest];
}
while (testScores[numTest] > 0);
//Calculate Average
average = total/numTest;
System.out.println("class average is : "+average);
System.out.print("Test Score");
System.out.println();
//Display Result
for(int i=1;i<=25;i++)
{
System.out.print(i+" "+testScores[i]);
System.out.println();
}
}//end of main
}// end of Class
Explanation / Answer
PROGRAM:
import java.util.Scanner;
import java.io.*;
public class testScore
{
public static void main(String [] args)
{
//local constant
int MAXSIZE=25;
int numTest = -1;
int total = 0;
//local variables
float average;
int testScores[] = new int [MAXSIZE];
Scanner in= new Scanner(System.in);
//***************************************************************************************//
do
{
//Increment number of test
numTest++;
//Ask user to enter test score
System.out.println("Enter Test score of Test: " + (numTest+1) + " < -1 to exit > ");
testScores[numTest]=in.nextInt();
total= total + testScores[numTest];
}
while (testScores[numTest] > 0);
//Calculate Average
average = (float)total/numTest+1;
System.out.println("class average is : "+average);
System.out.print("Test Score");
System.out.println();
//Display Result
for(int i=0;i<numTest;i++)
{
System.out.print(i+1+" "+testScores[i]);
System.out.println();
}
}//end of main
}// end of Class
OUTPUT:
run:
Enter Test score of Test: 1 < -1 to exit >
450
Enter Test score of Test: 2 < -1 to exit >
125
Enter Test score of Test: 3 < -1 to exit >
363
Enter Test score of Test: 4 < -1 to exit >
236
Enter Test score of Test: 5 < -1 to exit >
-1
class average is : 294.25
Test Score
1 450
2 125
3 363
4 236
BUILD SUCCESSFUL (total time: 10 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.