1. Member Join Date
May 2012
Posts
2
Rep Power
0 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?  Reply With Quote

2. 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  Reply With Quote

3. Member Join Date
May 2012
Posts
2
Rep Power
0 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;
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  Reply With Quote

4. Re: array problem

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

kind regards,

Jos  Reply With Quote Posting Permissions

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