Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program 4.1. Write a program to determine the percentage of A, B, C, and F score

ID: 3822819 • Letter: P

Question

Program 4.1. Write a program to determine the percentage of A, B, C, and F scores assigned in a class Your program should input the grades into an array of scores. The maximum class size is 100 students Prompt the user to input scores. After inputting the scores into the score array, go through the array and compute the number of A, B, C, and NC scores and display the percentage of each to the user. Program Requirement: 1. Score range: A: 90-100 B: 80-89 C: 70-79 NC: 0- 69 2. You must use an array in your solution. 3. Scores are integer values and percentages should be real numbers (float) with 2 digits of precision after the decimal point. 4. There may be fewer than 100 scores. You can decide how to determine the number of scores (options to consider are: asking the user for the number of scores, prompting the user if they have more scores to enter, and asking the user to specify an invalid number (a terminator value) when they are done entering scores) Extra credit: Sort the scores from highest to lowest and display the scores in descending order. Display the scores and the letter grades. Only scores between 0 and 100 are valid. When the user enters a score, check to see if it is valid. If not, tell the user that the score is invalid and continually prompt user to enter a correct score until a valid one has been entered. Sample input: 85, 99, 50, 78, 94, 92, 82 (provided by user-you can decide how to format the input) Sample output (You can decide how to format the output)

Explanation / Answer

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Scores {
   public static void main(String args[]){
       ArrayList<Double> arr = new ArrayList<Double>();
       Scanner sc = new Scanner(System.in);
       double marks;
       while(true){
           System.out.println("Enter grades for the students (-1 to stop entering) ");
           marks = sc.nextDouble();
           if(marks == -1){
               break;
           }
           else if(marks < -1)
           {
               System.out.println("You have entered wrong data. please enter again");
           }
           else{
               arr.add(marks);
           }
       }
      
       Collections.sort(arr);
       double sum=0;
       double sumA = 0, sumB = 0, sumC = 0, sumD = 0;
       for(int i=0;i<arr.size();i++){
           sum =sum+arr.get(i);
           if(arr.get(i)>=90 && arr.get(i)<=100)
               sumA =sumA +arr.get(i);
           else if (arr.get(i)>=80 && arr.get(i)<=89)
               sumB = sumB + arr.get(i);
           else if(arr.get(i)>=70 && arr.get(i)<=79)
               sumC = sumC + arr.get(i);
           else
               sumD = sumD + arr.get(i);
       }
       System.out.println(sum);
       System.out.println(sumA);
       System.out.println(sumB);
       System.out.println(sumC);
       System.out.println(sumD);
       double percentA = (sumA/sum)*100;
       double percentB = (sumA/sum)*100;
       double percentC = (sumA/sum)*100;
       double percentD = (sumA/sum)*100;
       System.out.println("Percentage of A's: "+percentA);
       System.out.println("Percentage of B's: "+percentB);
       System.out.println("Percentage of C's: "+percentC);
       System.out.println("Percentage of NC's: "+percentD);
       System.out.println("Score       Grade");
       for(int i=arr.size()-1;i>=0;i--){
           if(arr.get(i)>=90 && arr.get(i)<=100)
               System.out.println(arr.get(i)+"           "+"A");
           else if (arr.get(i)>=80 && arr.get(i)<=89)
               System.out.println(arr.get(i)+"           "+"B");
           else if(arr.get(i)>=70 && arr.get(i)<=79)
               System.out.println(arr.get(i)+"           "+"C");
           else
               System.out.println(arr.get(i)+"           "+"NC");
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote