Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   How to make a java program that gets average test scores? (http://www.go4expert.com/forums/java-program-average-test-scores-t29589/)

johnsonparkar224 2Apr2013 14:45

How to make a java program that gets average test scores?
 
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.

coderzone 2Apr2013 14:53

Re: How to make a java program that gets average test scores?
 
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.

programmingtutor 5Apr2013 10:25

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

Originally Posted by johnsonparkar224 (Post 99374)
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?

coderzone 6Apr2013 11:38

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

Originally Posted by programmingtutor (Post 99408)
Hi, do you still need help with your problem?

Any reason for asking that

georgemaravich 5Dec2014 13:43

Re: How to make a java program that gets average test scores?
 
Try reading Java How to Program by Dietel. There's a similar code there for computing average tests...

alia123 17Feb2016 11:01

Re: How to make a java program that gets average test scores?
 
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);


boyiajas@gmail.com 22Feb2016 14:09

Re: How to make a java program that gets average test scores?
 
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();
        }
}



All times are GMT +5.5. The time now is 21:39.