How to make a java program that gets average test scores?

johnsonparkar224's Avatar
Newbie Member
I need help making a java program that will allow me to input 10 test grades into an array using a dialog box in one method. Then in a different method it needs to display the grades and calculate the average, highest, and lowest grade. I have no idea where to start and need a lot of help please.
0
coderzone's Avatar, Join Date: Jul 2004
Team Leader
Try getting this done in a console based Java Program and once you have the logic done, you can always get it in the dialog box.
0
programmingtutor's Avatar
Newbie Member
Quote:
Originally Posted by johnsonparkar224 View Post
I need help making a java program that will allow me to input 10 test grades into an array using a dialog box in one method. Then in a different method it needs to display the grades and calculate the average, highest, and lowest grade. I have no idea where to start and need a lot of help please.
Hi, do you still need help with your problem?
0
coderzone's Avatar, Join Date: Jul 2004
Team Leader
Quote:
Originally Posted by programmingtutor View Post
Hi, do you still need help with your problem?
Any reason for asking that
0
georgemaravich's Avatar, Join Date: Dec 2014
Newbie Member
Try reading Java How to Program by Dietel. There's a similar code there for computing average tests...
0
alia123's Avatar, Join Date: Jan 2016
Contributor
Hey, try this one using loop :
Code:
double total;
for(int student = 1; student <= 4; student++) {
    System.out.printf("Student %d\n", student);
    double sum = 0, count = 0;

    while(true) {
        System.out.printf("Enter your score: ");
        double input = scanner.nextDouble();
        if(input == -1) break;
        sum += input;
        count++;
    }
    total += sum;

    System.out.printf("Average: %.2f\n", sum / count);
}

System.out.printf("Total: %.2f\n", total);
0
boyiajas@gmail.com's Avatar, Join Date: Nov 2015
Newbie Member
check this out:
Code:
/*
 * java program that will allow me to input 10 test grades into an array using a dialog box in one method.
 * Then in a different method it needs to display the grades and calculate the average, highest, and lowest grade
 */
import javax.swing.JOptionPane;

public class input10testgrades
{
	private final int studentGrades[] = new int[10];
	private double average;
	
	public void inputStudentGrades()
	{
		for(int i = 0; i < studentGrades.length; i++)
		{
			studentGrades[i] = Integer.parseInt(JOptionPane.showInputDialog(null));
		}
	}
	public void displayGrade()
	{
		System.out.println("This are all the test grades\n=================================");
		for(int i = 0; i < studentGrades.length; i++)
		{
			System.out.println(studentGrades[i]);
		}
		
		System.out.println("\n\nThe total average of grades\n=================================");
		
		double gradesSum = 0;
		int highestNum = 0;
		int lowestNum = studentGrades[0]; //here we are getting the first grade test
		
		for(int grade : studentGrades)
		{
			gradesSum+=(double)grade; //here we are getting the total sum of all the test grade
			
			//here am checking for the highest number
			if(grade > highestNum)
				highestNum = grade;
			//here am checking for the lowest number	
			if(grade < lowestNum)
				lowestNum = grade;
		}
		
		average = gradesSum/10; //here we are calculate the average of the total grade test
		System.out.println(average);
		System.out.println("\nThe Highest Grade Number is :"+highestNum);
		System.out.println("\nThe Lowest Grade Number is :"+lowestNum);
		
		
	}
	public static void main(String []grade)
	{
		input10testgrades testgrades = new input10testgrades();
		testgrades.inputStudentGrades();
		testgrades.displayGrade();
	}
}