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

Correct the few errors in the small example Java program. /* Problem: testprojec

ID: 3691214 • Letter: C

Question

Correct the few errors in the small example Java program.

/*

Problem:   testproject# 3

*/

import java.io.*;

public class testproject4

{
   public static void main(String args[]) throws IOException
   {
       Hw9 app;
       app = new Hw9();
       app.appMain();
   }   // end main()
}

class Hw9
{
   /* Instance Data Declarations, so declare the variables HERE */
   BufferedReader stdin;   // define stdin

int stuID, hours, totStus, totStuHours, hiGpaStuID;
  
   float avgStuHours, gpa, hiGpa;

   String term, inString;
  
   /* appMain module calls for initialization, processing, output */
   public void appMain() throws IOException
   {
       initializeReport();
       displayHeader();
       getTerm() ;
      
       while (stuID != -1)
       {
           procStudent();
       }
      
       calcAvg();
       displaySummary();
   } // end of appMain

   void initializeReport()
   {
   /* Initialize variables here */
stdin = new BufferedReader(new InputStreamReader(System.in));
   // create standard input object

       totStus = 0;
       totStuHours = 0;
       hiGpa = 0;
       stuID = 0; // Any non-flag value
}

   void displayHeadere()
   {
       System.out.println(" *********************");
       System.out.println("Solution for HW #9");
       System.out.println("by user");
       System.out.println("********************* ");
}

   void getTerm() throws IOException
   {
       System.out.print("Please enter the semester term: ");
       term = stdin.readLine();
   }

   void procStudent() throws IOException
   {
       getStuId();
       if (stuID != -1)
       {
           getStuDetails();
           calcTotals();
           updateHigh();
           displayDetails();
       }
   }

   void getStuId() throws IOException
   {
       System.out.print("Enter the student ID code: ");
       inString = stdin.readLine();
       stulD= Integer.parselnt(inString);
   }

   void getStuDetails() throws IOException
   {
       System.out.print("Enter the student's GPA: ");
       inString = stdin.readLine();
       gpa = Float.parseFloat(inString);

       System.out.print("Enter the number of hours completed by the student: ");
       inString = stdin.readLine();
       hours = Integer.parselnt(inString);
   }

   void calcTotals()
   {
       totStus = totStus + 1;
       totStuHours = totStuHours + hours;
   }

   void updateHigh()
   {
       if (hiGpa < gpa)
       {
           hiGpa = gpa;
           hiGpaStulD = stuID;
       }
   }
   void displayDetails()
    {
   System.out.println(" ******* Student Details *******") ;
        System.out.println("Student ");
   System.out.println("Code GPA Hours");
   System.out.println(stulD + " " + gpa + " " + hours);
   System.out.println("******************************** ");
   }

   void ealcAvg()
   {
   avgStuHours = (float)totStuHours / totStus;
    }

   void displaySummary()
   {
       System.out.print(" ************ Semester Summary ******");

   System.out.println(" SEMESTER: " + term);
   System.out.println("Total number of students: " + totStus);
   System.out.println("Total number of student hours: " + totStuHours);
   System.out.println("Average number of student hours: " + avgStuHours);
   System.out.println(" Highest GPA: " + hiGpa);
   System.out.println("ID of student with high GPA: " + hippaStuID);
   System.out.println("************** ");
}
}

Explanation / Answer

import java.io.*;
class testproject4
{
public static void main(String args[]) throws IOException
{
Hw9 app;
app = new Hw9();
app.appMain();
}   
}

class Hw9
{

BufferedReader stdin;   
int stuID,hours,totStus,totStuHours,hiGpaStuID;   
float avgStuHours,gpa,hiGpa;
String term,inString;

public void appMain() throws IOException
{
initializeReport();
displayHeader();
getTerm() ;
  
while (stuID != -1)
{
procStudent();
}
  
calcAvg();
displaySummary();
}
void initializeReport()
{
stdin = new BufferedReader(new InputStreamReader(System.in));
totStus = 0;
totStuHours = 0;
hiGpa = 0;
stuID = 0;
}
void displayHeader()
{
System.out.println(" *********************");
System.out.println("Solution for HW #9");
System.out.println("by user");
System.out.println("********************* ");
}
void getTerm() throws IOException
{
System.out.print("Please enter the semester term: ");
term = stdin.readLine();
}
void procStudent() throws IOException
{
getStuId();
if (stuID != -1)
{
getStuDetails();
calcTotals();
updateHigh();
displayDetails();
}
}
void getStuId() throws IOException
{
System.out.print("Enter the student ID code: ");
inString = stdin.readLine();
stuID= Integer.parseInt(inString);
}
void getStuDetails() throws IOException
{
System.out.print("Enter the student's GPA: ");
inString = stdin.readLine();
gpa = Float.parseFloat(inString);
System.out.print("Enter the number of hours completed by the student: ");
inString = stdin.readLine();
hours = Integer.parseInt(inString);
}
void calcTotals()
{
totStus = totStus + 1;
totStuHours = totStuHours + hours;
}
void updateHigh()
{
if (hiGpa < gpa)
{
hiGpa = gpa;
hiGpaStuID = stuID;
}
}
void displayDetails()
{
System.out.println(" ******* Student Details *******") ;
System.out.println("Student ");
System.out.println("Code GPA Hours");
System.out.println(stuID + " " + gpa + " " + hours);
System.out.println("******************************** ");
}
void calcAvg()
{
avgStuHours = (float)totStuHours / totStus;
}

void displaySummary()
{
System.out.print(" ************ Semester Summary ******");
System.out.println(" SEMESTER: " + term);
System.out.println("Total number of students: " + totStus);
System.out.println("Total number of student hours: " + totStuHours);
System.out.println("Average number of student hours: " + avgStuHours);
System.out.println(" Highest GPA: " + hiGpa);
System.out.println("ID of student with high GPA: " + hiGpaStuID);
System.out.println("************** ");
}
}