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

THE PROGRAM MUST HAVE 3 DIFFERENT CLASSES Object relationship And File IO Write

ID: 665745 • Letter: T

Question

THE PROGRAM MUST HAVE 3 DIFFERENT CLASSES

Object relationship And File IO Write a program to perform statistical analysis of scores for a class of students. The class may have up to 40 students. There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is to be read from a text file. The output from the program should be similar to the following Here is some sample data (not to be used) for calculations: The program should print the lowest and highest scores for each quiz

Explanation / Answer

import java.io.*;

public class StudentReport {

public static void main (String [] args)

{

String fileName = "input.txt";

StudentList cs35 = new StudentList (fileName);

cs35.readIntput (fileName);

cs35.findReport ();

cs35.printReport ();

}

}

class StudentList

{

int [] Stu;

int [][] grade;

int nStu = -1;

int [] high = new int [5];

int [] low = new int [5];

double [] avg = new double [5];

  

public StudentList (String FileName)

{

try

{

FileInputStream fstream = new

FileInputStream(FileName);

DataInputStream in =

new DataInputStream(fstream);

while (in.available() != 0)

{

in.readLine();

nStu++;

}

in.close ();

fstream.close ();

Stu = new int [nStu];

grade = new int[nStu][5];

}

catch (Exception e)

{

System.out.println ("invalid input");

}

}

public void readIntput (String FileName)

{

try

{

FileInputStream fstream = new

FileInputStream(FileName);

DataInputStream in =

new DataInputStream(fstream);

//ignore the first line

in.readLine();

String row;

String [] sTemp;

int i = 0;

while (in.available() != 0)

{

row = in.readLine();

sTemp = row.split(" ");

Stu[i] = Integer.parseInt (sTemp[0]);

for (int j = 1; j < 6; j++)

grade [i][j - 1] = Integer.parseInt (sTemp[j]);

  

i++;

}

in.close ();

fstream.close ();

}

catch (Exception e)

{

System.out.println ("invalid input");

}

}

public void findReport ()

{

int i, j;

int tempMax;

int tempMin;

double tempAvg;

for (j = 0; j < 5; j++)

{

tempAvg = 0.0;

tempMax = 0;

tempMin = 100;

for (i = 0; i < nStu; i++)

{

if (tempMax < grade[i][j])

tempMax = grade[i][j];

if (tempMin > grade[i][j])

tempMin = grade[i][j];

tempAvg += grade[i][j];

}

tempAvg /= 5;

avg[j] = tempAvg;

high[j] = tempMax;

low[j] = tempMin;

}

}

public void printReport ()

{

int i;

int j;

System.out.println ("Stud Qu1 Qu2 Qu3 Qu4 Qu5 ");

for (i = 0; i < nStu; i++)

{

System.out.print (Stu[i]);

for (j = 0; j < 5; j++)

System.out.print (" " + grade[i][j]);

System.out.print (" ");

}

System.out.print (" High Score:");

for (i = 0; i < 5; i++)

System.out.print (" " + high[i]);

System.out.print (" Low Score:");

for (i = 0; i < 5; i++)

System.out.print (" " + low[i]);

System.out.print (" Average Score:");

for (i = 0; i < 5; i++)

System.out.print (" " + avg[i]);

  

}

}