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

Create a Java application in NetBeans that prompts the user to enter a length of

ID: 3688099 • Letter: C

Question

Create a Java application in NetBeans that prompts the user to enter a length of an array, and then prompts the user to enter that number of scores. The program then prints the scores, the lowest, highest, average, number of A’s, B’s C’s, D’s, F’s, and then prints the scores in descending order. Use the following method headers:

// print scores

    public static void printScores(int[] array)

// lowest score

    public static int lowestScore(int[] array)

// highest score

    public static int highestScore(int[] array)

// average score

    public static double averageScore(int[] array)

     

// count grades

    public static int countGrades(int[] array, char gradeType)

// print descending scores

    public static void printDescendingScores(int[] array)

Sample Java output:

Enter the length of the array:

5

Enter 5 scores:

65 78 75 98 87

Printed scores: 65 78 75 98 87

Low: 65

High: 98

Avg: 80.6

A's: 1

B's: 1

C's: 2

D's: 1

F's: 0

Scores in descending order: 98 87 78 75 65

Explanation / Answer

Test28.java


public class Test28 {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       java.util.Scanner in = new java.util.Scanner(System.in);
       System.out.println("Enter the length of an array");
       int length = in.nextInt();
       int arr[] = new int[length];
       System.out.println("Enter "+length+" scores :");
       for(int i=0; i<length; i++){
           arr[i] = in.nextInt();
       }
       printScores(arr);
       int min = lowestScore(arr);
   System.out.print("Low: "+min);
   System.out.println("");
       int max = highestScore(arr);
   System.out.print("High: "+max);
   System.out.println("");
       double avg = averageScore(arr);
   System.out.print("Avg: "+avg);
   System.out.println("");   
   char c[] = {'A', 'B', 'C', 'D', 'F'};
   int count = 0;
   for(int i=0; i<c.length; i++){
       count = 0;
       count = countGrades(arr, c[i]);
       System.out.println(c[i]+"'s: "+count);
   }
   printDescendingScores(arr);

   }
   // print scores
public static void printScores(int[] array){
   System.out.print("Printed Scores : ");
   for(int i=0; i<array.length; i++){
       System.out.print(array[i] +" ");
   }
   System.out.println("");
}

//lowest score
public static int lowestScore(int[] array){
   int min = array[0];
   for(int i=1; i<array.length; i++){
       if(min > array[i])
           min = array[i];
   }
return min;
}

//highest score
public static int highestScore(int[] array){
   int max = array[0];
   for(int i=1; i<array.length; i++){
       if(max < array[i])
           max = array[i];
   }
return max;   
}

//average score
public static double averageScore(int[] array){
   int sum = 0;
   for(int i=0; i<array.length; i++){
   sum = sum + array[i];
   }
   return ((double)sum/array.length);
}

//count grades
public static int countGrades(int[] array, char gradeType){
   int count = 0;
   for(int i=0; i<array.length; i++){
       if(array[i] <= 100 && array[i] >= 90 && gradeType == 'A')
           count++;
       else if(array[i] < 90 && array[i] >= 80 && gradeType == 'B')
           count++;
       else if(array[i] < 80 && array[i] >= 70 && gradeType == 'C')
           count++;
       else if(array[i] < 70 && array[i] >= 60 && gradeType == 'D')
           count++;
       else if(array[i] < 60 && gradeType == 'E')
           count++;
      
   }
   return count;
}

//print descending scores
public static void printDescendingScores(int[] array){
   int temp = 0;
for (int i = 0; i < array.length; i++)
{
for (int j = i + 1; j < array.length; j++)
{
if (array[i] < array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
System.out.print("Scores in descending order: ");
for (int i = 0; i < array.length; i++)
{
System.out.print(array[i] + " ");
}
}

}

Output:

Enter the length of an array
5
Enter 5 scores :
65 78 75 98 87
Printed Scores : 65 78 75 98 87
Low: 65
High: 98
Avg: 80.6
A's: 1
B's: 1
C's: 2
D's: 1
F's: 0
Scores in descending order: 98 87 78 75 65