Java program to calculate grade ranges
import javax.swing.JOptionPane; public class ArrayProgram4 { public static void main(String[] args) { //create array based on the number of args entered by user String response = JOptionPane.showInputDialog(null, "Number ofscores:"); int number = Integer.parseInt(response); int scores[] = new int[number]; //for loop to convert String args array to integer myArray for (int a = 0; a < number; a++) { response = JOptionPane.showInputDialog(null, "Enter score"+(a+1)); scores[a] = Integer.parseInt(response); } int sum = 0; int largest = scores[0]; int smallest = scores[0]; int A = scores[0]; int B = scores[0]; int C = scores[0]; int D = scores[0]; int F = scores[0]; //for loop to find sum, largest, smallest, and number of each grades 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] < 100 && scores[i] > 90) { A = scores[i]; } if (scores[i] < 89 && scores[i] > 80) { B = scores[i]; } if (scores[i] < 79 && scores[i] > 70) { C = scores[i]; } if (scores[i] < 69 && scores[i] > 60) { D = scores[i]; } if (scores[i] < 59) { F = scores[i]; } } //output 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) is " + A/A + "\nThe number of students with " + "scores of 80-89 (B) is " + B/B + "\nThe number of students with " + "scores of 70-79 (C) is " + C/C + "\nThe number of students with " + "scores of 60-69 (D) is " + D/D + "\nThe number of students with " + "scores below 60 (F) is " + F/F); }
When i execute the program im not sure how to make it show the number of As, Bs, Cs, Ds, & Fs
Join our real-time social learning platform and learn together with your friends!