Results 1 to 4 of 4

Thread: array problem

  1. #1
    surgeon is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default array problem

    Write a program that allows the user to enter the number of students in the class and then the studentsí names followed by their exam scores and outputs the following information:

    a) Class score average.
    b) Names of all the students whose test scores are above the class score average.
    c) Highest exam score and the names of all the students having the highest score.


    can you help?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: array problem

    Sure; you go first and if you're stuck we'll try to help (please explain your specific problem(s)).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    surgeon is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: array problem

    Java Code:
    int NUMBER_OF_STUDENT =Integer.parseInt(JOptionPane.showInputDialog("enter numbers of student "));
        double[] scores = new double[NUMBER_OF_STUDENT];
        double sum = 0;
    
        java.util.Scanner input = new java.util.Scanner(System.in);
        for (int i = 0; i < NUMBER_OF_STUDENT; i++) {
          System.out.print("Enter a new score : ");
          scores[i] = input.nextDouble();
          sum += scores[i];
        }
        double average = sum / NUMBER_OF_STUDENT;
        int count = 0; // The number of elements above average
        for (int i = 0; i < NUMBER_OF_STUDENT; i++) 
          if (scores[i] > average)
            count++;
        double max = scores[0];
    for (int i = 1; i < scores.length; i++) {
      if (scores[i] > max) max = scores[i];
    }
    
        System.out.println("Average is " + average);
        System.out.println("Number of scores above the average "
          + count);   
        System.out.println("Highest exam score is "+max);
    this is the code but i don't know how to link scores with names

    (Names of all the students whose test scores are above the class score average.
    Highest exam score and the names of all the students having the highest score.)
    Last edited by JosAH; 05-16-2012 at 08:55 PM. Reason: added [code] ... [/code] tags

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: array problem

    Why don't you build a small class Student; it should have a name and a score attribute.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Some problem with the array
    By naveenpaul1987 in forum New To Java
    Replies: 2
    Last Post: 01-03-2012, 04:58 AM
  2. Replies: 0
    Last Post: 05-12-2011, 07:04 PM
  3. array problem
    By aizen92 in forum New To Java
    Replies: 26
    Last Post: 12-21-2010, 05:42 AM
  4. Array problem
    By Red727 in forum New To Java
    Replies: 2
    Last Post: 12-19-2010, 03:26 AM
  5. array problem
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 01:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •