69.4k views
4 votes
Write a program called GradesAverage, which prompts user for the number of students, reads it from the keyboard, and saves it in an int variable called numStudents. It then prompts user for the grades of each of the students and saves them in an int array called grades.

Your program must:
1. Make sure you store the grades entered in an array.
2. Compute the average in a separate method from the main().
3. Check the numStudents is a number, otherwise continue to prompt until they do.
4. Check the grade is between 0 and 100, otherwise continue to prompt until they do.
5. Have the user's entry from the console stay on the same line. (see example below)

User Imskm
by
6.4k points

1 Answer

3 votes

Answer:

See Explaination

Step-by-step explanation:

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class GradesAverage {

private static int checkNum(String num) {

int tmpNum;

try {

tmpNum = Integer.valueOf(num);

} catch(IllegalArgumentException e) {

System.out.println("You did not enter an integer.");

return -1;

}

return tmpNum;

}

private static boolean validNum(int num) {

if(num>=0 && num<=100) {

return true;

}

System.out.println("You did not enter an integer, try again

User Hainabaraka
by
6.2k points