Click here to Skip to main content
15,915,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Write a Java program that prompts a teacher for and inputs the number of students that took a test. The program should then establish two arrays of the size specified by the number of students. The first array should be of type String and hold the student names. The second array should be of type double and hold the grade each student achieved. The program should then prompt for and input the names and test scores for the number of students specified. The program should then calculate and display the class average on the test and a list of students that achieved a score at or above the average. A sample run of the program would appear as follows.

How many students took the test: 5

Student 1 name: Blake
Student 1 score: 88
Student 2 name: Charlie
Student 2 score: 72
Student 3 name: Joseph
Student 3 score: 91
Student 4 name: Mike
Student 4 score: 82
Student 5 name: Ricky
Student 5 score: 90

The average score is: 84.6

The student that scored at or above the average are:

Blake
Joseph
Ricky

What I have tried:

import java.util.Scanner;
public class JavaApplication46 {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number of students: ");

int numOfStu = input.nextInt();

int[] grades = new int[numOfStu];
String[] names = new String[numOfStu];

int grade = 0;
String name = "";

for(int i = 0; i < numOfStu; i++){
name = input.next();
grade = input.nextInt();
names[i] = name;
grades[i] = grade;
System.out.println("");
}
Posted
Updated 13-Dec-17 5:17am
v2
Comments
F-ES Sitecore 13-Dec-17 9:16am    
We're not here to do your homework for you.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
You should add up grade[i] to grade
grade+=grades[i];

In the end you can get the average like this
System.out.println("Average is "+grade/numOfStu);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900