1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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:
    734
    Likes Received:
    37
    Trophy Points:
    0
    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:
    734
    Likes Received:
    37
    Trophy Points:
    0
    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:
    3
    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();
    	}
    }
    
     

Share This Page