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

Discussion in 'Java' started by johnsonparkar224, Apr 2, 2013.

  1. johnsonparkar224

    johnsonparkar224 New Member

    Joined:
    Apr 2, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    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.
     
  3. programmingtutor

    programmingtutor New Member

    Joined:
    Apr 5, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi, do you still need help with your problem?
     
  4. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    Any reason for asking that
     
  5. georgemaravich

    georgemaravich New Member

    Joined:
    Dec 2, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Try reading Java How to Program by Dietel. There's a similar code there for computing average tests...
     
  6. alia123

    alia123 New Member

    Joined:
    Jan 8, 2016
    Messages:
    65
    Likes Received:
    5
    Trophy Points:
    0
    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);
     
  7. boyiajas@gmail.com

    boyiajas@gmail.com New Member

    Joined:
    Nov 10, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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();
    	}
    }
    
     
  8. Jeff Ronald

    Jeff Ronald Member

    Joined:
    Dec 9, 2016
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    6
    Gender:
    Male
    Home Page:
    http://ezmoov.com
    If this is your first introduction to Java I would suggest ignoring the fact you want a dialog box and make a simple console application to begin with. Once this is working correctly you can then put this into a GUI.
     
  9. sayalipatil

    sayalipatil New Member

    Joined:
    Dec 18, 2018
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Female
    Home Page:
    https://crbtech.in/online-java-training-course
    Code:
    import java.util.Scanner;
    
    public class AverageTestScore
    {
       public static void main(String[] args)
       {
           //create the variables
           int TestScore1;
           int TestScore2;
           int TestScore3;
           int TestScore4;
           int TestScore5;
           float AverageScore;
        
           //create keyboard for input
           Scanner Keyboard = new Scanner(System.in);
        
           //Ask the user for the 5 test scores
           System.out.println("Please enter test score 1");
           TestScore1 = Keyboard.nextInt();
        
           System.out.println("Please enter test score 2");
           TestScore2 = Keyboard.nextInt();
        
           System.out.println("Please enter test score 3");
           TestScore3 = Keyboard.nextInt();
        
           System.out.println("Please enter test score 4");
           TestScore4 = Keyboard.nextInt();
        
           System.out.println("Please enter test score 5");
           TestScore5 = Keyboard.nextInt();
        
           //Calculate the average score for the tests
           AverageScore = ((TestScore1 + TestScore2 + TestScore3 + TestScore4 + TestScore5)/5);
        
           //Display Average test Score
           System.out.println("The average score of the 5 tests is " + AverageScore);
       }
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice