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

Java Progress Report class Student DATA FIELDS -name: String -grade: char -avera

ID: 3663354 • Letter: J

Question

Java Progress Report

class Student

DATA FIELDS

-name: String

-grade: char

-average: double

-scores[5]: int

Store the name of the student

Store the letter grade the student has

Store the average score

Store the five exam scores for the student

METHODS

Constructors

Accessor methods

Modifiers methods

+calculateAverage(): void

+calculateGrade(): void

Make whatever constructors will be useful to completing the assignment

Determine the average of the five test scores for each student

Determine each student’s letter grade based on 90-100 A, 80-89 B, 70-79 C, 60-69 D, 0-59 F

The input file has students’ exam scores for two class sections. The input file has the following format

int                                                                       <= Number of students in the first section

String(name) int int int int int      <= Data for each student

int                                                                       <= Number of students in the second section

String(name) int int int int int      <= Data for each students

class ProgressReport

DATA FIELDS

-sectionArray: Student [2][];

2D array storing Student objects for two sections

Each row of the array represents a particular section and each column represents an individual student of that section

METHODS

Constructors

Accessor methods

Modifiers methods

+readInputFile(): void

+generateReport(): void

+sortByName(): void

+binarySearch(int section, String searchName): Student

Read data from the input file, “Lab5A.in”, instantiate Student objects, and initialize data fields of the students using the data in the input file. The number of columns of each row of the 2D array should be set after reading the line informing the number of students in each section from the input file.

Create a progress report referencing the sample output below. This method prints out student name, average exam score, and letter grade of each student in the order of the input file, section by section, to the console.

Sort the array, sectionArray, in ascending order based on the student name.

Implement a binary search that searches and returns the Student object whose name matches with the input argument, searchName. If there is no matching student’s name, return null. The first input argument, section, represents the section number that confines the search scope.

Download the driver file, “ProgressReportDriver.java”, from the course Web site and review the statements in the main method. Incorporate the driver file with your class files and execute the application. Your application should print out the same result on the screen shown below.

Progress Report

Section 1

Johnson 90.6 A

Aniston 81.2 B

Cooper_ 82.2 B

Gupta__ 72.2 C

Blair__ 52.2 F

Section 2

Clark__ 59.2 F

Kennedy 63.4 D

Bronson 90.0 A

Sunny__ 84.8 B

Smith__ 75.4 C

Diana__ 68.8 D

AFTER SORTING THE 2D ARRAY

Progress Report

Section 1

Aniston 81.2 B

Blair__ 52.2 F

Cooper_ 82.2 B

Gupta__ 72.2 C

Johnson 90.6 A

Section 2

Bronson 90.0 A

Clark__ 59.2 F

Diana__ 68.8 D

Kennedy 63.4 D

Smith__ 75.4 C

Sunny__ 84.8 B

SEARCH TEST

Found Cooper_ Average = 82.2    Grade = B

Fail to find the student

Found Diana__ Average = 68.8    Grade = D

class Student

DATA FIELDS

-name: String

-grade: char

-average: double

-scores[5]: int

Store the name of the student

Store the letter grade the student has

Store the average score

Store the five exam scores for the student

METHODS

Constructors

Accessor methods

Modifiers methods

+calculateAverage(): void

+calculateGrade(): void

Make whatever constructors will be useful to completing the assignment

Determine the average of the five test scores for each student

Determine each student’s letter grade based on 90-100 A, 80-89 B, 70-79 C, 60-69 D, 0-59 F

Explanation / Answer


//Student.java
public class Student
{
   private String name;
   private char grade;
   private double average;
   private int[] scores=new int[5];
  
   public Student(String name)
   {
       this.name=name;  
   }
  
  
   public Student(String foundName, int[] foundScores)
   {
       name=foundName;
       for (int i = 0; i < scores.length; i++)
       {
           this.scores[i]=foundScores[i];
       }
   }


   public void setScores(int scores[])
   {
       for (int i = 0; i < scores.length; i++)
       {
           this.scores[i]=scores[i];
       }
   }
  
   public void setName(String name)
   {
       this.name=name;
   }
   public String getName()
   {
       return name;
   }
  
   public void calculateAverage(double sum, int size)
   {
      
       average= sum/size;
   }
  
   public double getAverage()
   {
       return average;
   }
  
   public void calculateGrade()
   {
      
       if(average>=90 && average<=100)
           grade='A';
       else if(average>=80 && average<=89)
           grade='B';
       else if(average>=70 && average<=79)
           grade='C';
       else if(average>=60 && average<=69)
           grade='D';
       else
           grade='F';
      
   }
  
   public char getGrade()
   {
       return grade;
   }
  
   public int[] getScores()
   {
       return scores;
   }
  
   @Override
   public String toString() {      
       return name+" "+average+" "+grade;
   }
  
}
------------------------------------------------------------------------------------------------------------------------------------
//ProgressReport.java
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class ProgressReport
{

   private static final boolean ProgressReport = false;
   private Student[][] sectionArray = new Student[2][];

   public Student[][] getSectionArray()
   {
       return sectionArray;
   }

   public void setSectionArray(Student[][] sectionArray)
   {
       this.sectionArray = sectionArray;
   }

  
   //Method to read input file Lab4A.txt in sectionArray
   public void readInputFile() throws NumberFormatException, IOException
   {      
       int [] studentScores = new int[5];           
       File studentData = new File("Lab4A.txt");
       Scanner studentList = new Scanner(studentData);
       for (int row = 0; row < 2; row++)
       {
           int sectionLength = studentList.nextInt();
           sectionArray[row] = new Student[sectionLength];

           for (int column = 0 ;column < sectionLength; column++){
               double scoreSum = 0;
               Student student = new Student(studentList.next());
               for (int score = 0; score < studentScores.length; score++){
                   studentScores[score] = studentList.nextInt();               
                   scoreSum = scoreSum + studentScores[score];                       
               }              
               student.setScores(studentScores);               
               student.calculateAverage(scoreSum, studentScores.length);               
               student.calculateGrade();                
               sectionArray[row][column] = student;  
           }
       }
   }

   public void generateReport(){
       System.out.println( "Progress Report" );

       for( int i = 0; i < this.sectionArray.length; i++){
           System.out.println();
           System.out.println( "Section " + (i+1) );

           for( final Student student : this.sectionArray[i] ){
               System.out.print( student.getName() +" " );
               System.out.print( student.getAverage() +" " );
               System.out.println( student.getGrade() );
           }
       }
   }

   public static boolean isProgressReport() {
       return ProgressReport;
   }

   public void sortByName()
   {
       String temp;
       for(int i = 0; i < 2; i++)
       {
           for (int a = 0; a < sectionArray[i].length-1; a++)
           {
               if (sectionArray[i][a].getName().compareToIgnoreCase(sectionArray[i][a+1].getName()) > 0)
               {
                   temp = sectionArray[i][a].getName();
                   sectionArray[i][a].setName(sectionArray[i][a+1].getName());
                   sectionArray[i][a+1].setName(temp);

               }
           }
       }

   }

   //Returns Student object if searchName is found
   //otherwise returns null
   public Student binarySearch(int section, String searchName){
       Student Found = null;
       int first = 0;
       int last;
       int middle;
       boolean found = false;

       last = sectionArray[section].length-1 ;
       middle = (first + last) / 2;
       while(!found && first <= last)
       {                              
           if(sectionArray[section][middle].getName().compareToIgnoreCase(searchName)>0)
               first=middle+1;
           else if(sectionArray[section][middle].getName().compareToIgnoreCase(searchName)<0)
               last=middle-1;
           else if (sectionArray[section][middle].getName().equals(searchName))
           {
               found = true;
               Found = sectionArray[section][middle];
           }  
          
           middle = (first + last) / 2;
          
       }  
       return Found;
   }
}

------------------------------------------------------------------------------------------------------------------------------------
import java.io.IOException;

//Driver program that tests the Student and ProgressReport class.
//ProgressReportDriver.java
public class ProgressReportDriver
{
   public static void main(String[] args) throws NumberFormatException, IOException
   {
       //Create an instance of ProgressReport
       ProgressReport pr=new ProgressReport();
      
       //Call readInputFile
       pr.readInputFile();
       //Call generateReport to print students report
       pr.generateReport();
       //Search for name
       String search="Johnson";
       //Call method binarySearch in section 0
       Student student=pr.binarySearch(0, search);
      
       //Sort students by name
       pr.sortByName();
       System.out.println("SEARCH TEST");
       if(student!=null)
       {          
           System.out.println("Found "+student.toString());                      
       }
       else
           System.out.println("Fail to find the student");
              
       System.out.println("AFTER SORTING THE 2D ARRAY");
       //print report after sorting
       pr.generateReport();
   }
}
------------------------------------------------------------------------------------------------------------------------------------
Sample input file
Lab4A.txt

5
Johnson 90 80 50 60 70
Aniston 81 85 60 90 42
Cooper 82 60 90 85 52
Gupta 72 85 74 96 90
Blair 52 85 52 60 63

5
Clark 55 84 75 95 96
Kennedy 65 85 45 95 65
Bronson 90 80 90 80 40
Sunny 45 65 85 90 85
Smith 40 55 65 75 70
Diana 95 85 75 85 85

Sample output
Progress Report

Section 1
Johnson 70.0 C
Aniston 71.6 C
Cooper 73.8 C
Gupta 83.4 B
Blair 62.4 D

Section 2
Clark 81.0 B
Kennedy 71.0 C
Bronson 76.0 C
Sunny 74.0 C
Smith 61.0 D
SEARCH TEST
Found Aniston 70.0 C
AFTER SORTING THE 2D ARRAY
Progress Report

Section 1
Aniston 70.0 C
Cooper 71.6 C
Gupta 73.8 C
Blair 83.4 B
Johnson 62.4 D

Section 2
Clark 81.0 B
Bronson 71.0 C
Kennedy 76.0 C
Smith 74.0 C
Sunny 61.0 D

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