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

import javax.swing.*; import java.awt.*; import java.util.Scanner; public class

ID: 3777090 • Letter: I

Question

import javax.swing.*;
import java.awt.*;
import java.util.Scanner;
public class GradeDriver{
   public static void main(String[] args) {
       System.out.println("********************************");
       System.out.println("* Welcome to the grade report! *");
       System.out.println("********************************");
       Scanner scan = new Scanner(System.in);
       System.out.print("How many grades will you enter (-1 to quit)>");
       int numGrades = scan.nextInt();
       int[] grades = new int[numGrades];
       int[] passingGrades = new int[numGrades];
       int[] failingGrades = new int[numGrades];
              
       do { //-1 to quit doesn't work
           do { //doesn't print "Enter score 2>" after entering score 1
               System.out.print("Enter the passing grade>55");
               int counter = 1;
               System.out.print(" Enter score " + counter + ">");
               int gradeEntered = scan.nextInt();
               System.out.println();
               double total = 0.0;
               for (int i = 0; i                    counter++;
              
                   if (gradeEntered>0) {
                       grades[i] = scan.nextInt();
                       total += (double) grades[i];
                  
                       if (gradeEntered>=55) {
                           grades[i] = passingGrades[i];
                       }
                  
                       else { //less than 55
                           grades[i] = failingGrades[i];
                       }
                  
                   }
                   else {
                       System.out.print(" Enter score " + counter + ">");
                   }
               }
           }while(numGrades>0);
          
           System.out.println("GRADE REPORT");
           System.out.println("============");
           System.out.println("Overall average: " + ArrayHelper.findAvg(grades,0,grades.length-1));
           System.out.println(" Failing grades (<55)");
           System.out.println("-------------------------------");
      
           for (int i=0; i                do {
                   System.out.println(failingGrades[i]);
               }while (failingGrades[i]!=0);
           }

           System.out.println(" Lowest failing grade: " + ArrayHelper.findMin(failingGrades,0,grades.length-1));
           System.out.println("Highest failing grade: " + ArrayHelper.findMax(failingGrades,0,grades.length-1));
           System.out.println("Average failing grade: " + ArrayHelper.findAvg(failingGrades,0,grades.length-1));
           System.out.println(" Passing grades (>= 55)");
           System.out.println("------------------------------- ");
      
           for (int i=0; i                do {
                   System.out.println(passingGrades[i]);
               }while (passingGrades[i]!=0);
           }
      
           System.out.println(" Lowest passing grade: " + ArrayHelper.findMin(passingGrades,0,grades.length-1));
           System.out.println("Highest passing grade: " + ArrayHelper.findMax(passingGrades,0,grades.length-1));
           System.out.println("Average passing grade: " + ArrayHelper.findAvg(passingGrades,0,grades.length-1));
          
           System.out.println(" Create another report?");
           System.out.print("How many grades will you be enter (-1 to quit)?>");
      
   } while(numGrades!=-1);
  
   System.out.println("Thanks for using the grade reporter!");
      
   }

}

//Here is the other class:

public class ArrayHelper {
   public static int sortIntoGroups(int[] arrayToSort, int partitionValue) {
       int[] sortedArray = new int[arrayToSort.length];
       int partitionIndex = 0;
       int j=0;
       int[] firstGroup = new int[arrayToSort.length];
       int[] secondGroup = new int[arrayToSort.length];
      
       for (int i=0; i            if (arrayToSort[i] < partitionValue) {
               firstGroup[i]=arrayToSort[i];
           }
           else if (arrayToSort[i] >= partitionValue) {
               secondGroup[i]=arrayToSort[i];
           }

           if(firstGroup[i]!=0){
               sortedArray[j++]=firstGroup[i];
           }
           else if(sortedArray[i]!=0) {
               sortedArray[j++]=secondGroup[i];
           }
       }
           partitionIndex = sortedArray[0];
           return partitionIndex; //return the first occurence of value which is less than the paritionvalue
   }
   public static double findAvg(int[] arrayToAvg, int startingIndex, int endingIndex) {
       double total=0.0;
       for (int j=startingIndex; j<=endingIndex; j++) {
           total+=arrayToAvg[j];
       }
       return total/(endingIndex-startingIndex+1);
   }
  
   public static int findMin(int[] array, int startingIndex, int endingIndex) {
       int minValue = array[startingIndex];
      
       for (int k=startingIndex; k<=endingIndex; k++) {
           if (array[k] < minValue) {
               minValue=array[k];
           }
       }
       return minValue;
   }
  
   public static int findMax(int[] array, int startingIndex, int endingIndex) {
       int maxValue = array[startingIndex];
      
       for (int k=startingIndex; k<=endingIndex; k++) {
           if (array[k] > maxValue) {
               maxValue = array[k];
           }
       }
       return maxValue;
   }
}

2. Grade Driver Your GradeDriver is to be an application that can be used by teachers and instructors to provide a report on the grades for a class. You should do your best to make the output well-structured and easy to read. Use whitespace and extra characters (e.g., or -1 to provide wel formatted output. As in the example above your program will ask the user to enter a number for how many grades they will be entering for a report: they may enter -1 to quit. Next, the program will ask for a passing grade; all grades lower than this value will be treated as a failing grade: ollgrades greater than or equal to this value wil be a passing grade. The program wil then ask for the exoct number of grades to be entered individuolly. For the passing grade and individualgrades, the program will not continue unless apositive number is entered fie if the user enters a negative number by mistake, the program wil simply ask them to repeat it: see the image above for an example). After all grades have been entered, a report will be displayed. The report will display the following information: The overall average (rounded to exacty two decimol places). For failing grades o The list of grades that foled no particular order) or the messoge "There were no failing grades. o The overage volue of grades that faaed lrounded to exactly two decimol places). o The minimum failing grade. o The maximum foing grade. For passing grades o Thelist of grades that passed (in no particular order or the message "There were no passing grades", o The average value of grades that passed rounded to exactly two decimal places). o The minimum passing grade. o The maximum passing grade.

Explanation / Answer

GradeDriver.java

import java.util.Scanner;

public class GradeDriver {

   public static void main(String[] args) {
       int no_of_grades,passing_grade;
   Scanner sc=new Scanner(System.in);
   System.out.println("**********************************");
   System.out.println("* Welcome to the Grade Reporter! *");
   System.out.println("**********************************");
   System.out.print(" How many grades will you enter(-1 to quit) >");
   no_of_grades=sc.nextInt();
   if(no_of_grades==-1)
       System.exit(0);
   else
   {
       System.out.print("Enter the passing grade :");
       passing_grade=sc.nextInt();
       int i=0;
       int grades[]=new int[no_of_grades];
       while(i<no_of_grades)
       {
           System.out.print("Enter Score "+(i+1)+">");
       grades[i]=sc.nextInt();
       if(grades[i]<0)
           continue;
       i++;
       }
       ArrayHelper ah=new ArrayHelper();
       System.out.println("Grade Report");
       System.out.println("-----------");
       System.out.println("Overall average :"+ah.calAverage(grades));
       ah.calfailingGradesReport(grades,passing_grade);
       ah.calPassingGradesReport(grades,passing_grade);
   }
  

   }

}

____________________

ArrayHelper.java

import java.text.DecimalFormat;

public class ArrayHelper {

   //This method will calculate the average
   public double calAverage(int arr[])
   {
       //Declaring variables
       float average=0,sum=0;
      
       //This for loop will calculate the sum
       for(int i=0;i<arr.length;i++)
       {
           sum+=arr[i];
       }
      
       //Calculate the average
       average=sum/arr.length;
       return average;
   }
  
   //This will display the failing grade report
   public void calfailingGradesReport(int arr[],int passgrade)
   {
       //Calling the method which will sort the array in ascending order
arr=sort(arr);
         
       System.out.println("Failing Grades (<"+passgrade+")");
       System.out.println("-------------------");
       for(int i=0;i<arr.length;i++)
       {
           if(arr[i]<passgrade)
           System.out.println(arr[i]);
       }
      
       int min=arr[0];
       int max=arr[0];
       float sum=0,average=0;
       int count=0;
       //This for loop will find the minimum and maximum failing grades
       for(int i=0;i<arr.length;i++)
       {
           if(arr[i]<passgrade)
           {
               count++;
               sum+=arr[i];
              
               if(arr[i]<min && arr[i]<passgrade)
   min=arr[i];
              
               if(arr[i]>max && arr[i]<passgrade)
       max=arr[i];  
           }
          
       }
      
       average=sum/count;
      
       //Displaying the lowest failing grade
       System.out.println(" Lowest Failing Grade :"+min);
      
       //Displaying the highest failing grade
       System.out.println("Highest Failing Grade :"+max);
      
       //Displaying the average failing grade
       System.out.printf("Average Failing Grade :%.2f ",average);
      
   }
  
   //This method will sort the array in the ascending order
   private int[] sort(int[] arr) {
       //This Logic will Sort the Array of elements in Ascending order
       int temp;
       for (int i = 0; i <arr.length; i++)
   {
   for (int j = i + 1; j <arr.length; j++)
   {
   if (arr[i] > arr[j])
   {
   temp = arr[i];
   arr[i] = arr[j];
   arr[j] = temp;
   }
   }
   }
       return arr;
   }
  
   //This will display the pasisng grade report
   public void calPassingGradesReport(int arr[],int passgrade)
   {
       arr=sort(arr);
       System.out.println(" Passing Grades (>="+passgrade+")");
       System.out.println("-------------------");
       for(int i=0;i<arr.length;i++)
       {
           if(arr[i]>=passgrade)
           System.out.println(arr[i]);
       }
      
       int min=arr[0];
       int max=arr[0];
       float sum=0,average=0;
       int count=0;
      
       //This for loop will find the minimum and maximum passing grades
       for(int i=0;i<arr.length;i++)
       {
           if(arr[i]>=passgrade)
           {
               count++;
               sum+=arr[i];
              
               if(arr[i]<min && arr[i]>=passgrade)
   min=arr[i];
              
               if(arr[i]>max && arr[i]>=passgrade)
       max=arr[i];  
           }
          
       }
      
       average=sum/count;
      
       //Displaying the lowest passing grade
       System.out.println(" Lowest Passing Grade :"+min);
      
       //Displaying the highest passing grade
       System.out.println("Highest Passing Grade :"+max);
      
       //Displaying the average passing grade
       System.out.printf("Average Passing Grade :%.2f ",average);
      
   }
}

_____________________

Output:

**********************************
* Welcome to the Grade Reporter! *
**********************************


How many grades will you enter(-1 to quit) >5
Enter the passing grade :55
Enter Score 1>-98
Enter Score 1>98
Enter Score 2>30
Enter Score 3>40
Enter Score 4>87
Enter Score 5>55
Grade Report
-----------
Overall average :62.0
Failing Grades (<55)
-------------------
30
40

Lowest Failing Grade :30
Highest Failing Grade :40
Average Failing Grade :35.00
Passing Grades (>=55)
-------------------
55
87
98

Lowest Passing Grade :30
Highest Passing Grade :98
Average Passing Grade :80.00

______Thank You