Java assignment, need guidance ...
I'm incredibly new to writing Java code. For my assignment, I have to use arrays to calculate the sum, average, largest, and smallest of any number of test scores. In addition, I have to use a "for loop" to tally up the number of A'S, B'S, C'S, D'S, and F'S (ex. "The number of students with scores of 90-100 (A) is 4", etc. for each letter grade) based on the test scores. All this has to be shown in a message box. I can calculate the sum, average, largest, and smallest parts of this assignment, but I can't get the latter half of the assignment done right. Instead of "The number of students with scores of 90-100 (A) is (insert calculated number here)" showing up, I get "The number of students with scores of 90-100 (A) is 0", and this happens for each letter grade I'm trying to determine. I'm not sure why the 0 is showing up. Here is my code:
import javax.swing.JOptionPane;
public class ArrayProject3 {
public static void main(String[] args) {
String response = JOptionPane.showInputDialog(null, "Number of scores:");
int number = Integer.parseInt(response);
int scores[] = new int[number];
for (int a = 0; a < number; a++) {
response = JOptionPane.showInputDialog(null, "Enter score " + (a+1));
scores[a] = Integer.parseInt(response);
}
int count = 0;
int gradeA = 0;
int gradeB = 0;
int gradeC = 0;
int gradeD = 0;
int gradeF = 0;
int sum = 0;
int largest = scores[0];
int smallest = scores[0];
for (int i = 0; i < scores.length; i++) {
sum = sum + scores[i];
if (scores[i] > largest) {
largest = scores[i];
}
if (scores[i] < smallest) {
smallest = scores[i];
}
if (scores[i] <= 90 && scores[i] >= 100){
gradeA = count++;}
if (scores[i] <= 80 && scores[i] >= 89){
gradeB = count++;}
if (scores[i] <= 70 && scores[i] >= 79){
gradeC = count++;}
if (scores[i] <= 60 && scores[i] >= 69){
gradeD = count++;}
if (scores[i] <= 60){
gradeF = count++;}
}
JOptionPane.showMessageDialog(null, "The sum is " + sum
+ "\nThe average is " + (sum / scores.length)
+ "\nThe largest is " + largest
+ "\nThe smallest is " + smallest
+ "\nThe number of students with scores of 90-100 (A) " + gradeA
+ "\nThe number of students with scores of 80-89 (B) " + gradeB
+ "\nThe number of students with scores of 70-79 (C) " + gradeC
+ "\nThe number of students with scores of 60-69 (D) " + gradeD
+ "\nThe number of students with scores below 60 (F) " + gradeF);
}
}