A java program rewrite with solution

Anonymous
timer Asked: Aug 3rd, 2018
account_balance_wallet $20

Question description

This assignment is built using the code from Assignment 5.

In this assignment create a separate serialized file using ObjectOutputStream for each student.

File should contain student's score and statistics for entire class.

Using debug mode (with Debug flag) print the contents of the serialized file.

  1. Print student statistics.
  2. Print scores for a given student id.
  3. implement the Debug flag globally



Complete Program:

// Student.java
import java.io.Serializable;
public class Student implements Serializable
{
private int Stud;
private int Qu1;
private int Qu2;
private int Qu3;
private int Qu4;
private int Qu5;

public Student(int stud, int qu1, int qu2, int qu3, int qu4, int qu5)
{
Stud = stud;
Qu1 = qu1;
Qu2 = qu2;
Qu3 = qu3;
Qu4 = qu4;
Qu5 = qu5;
}
public int getStud()
{
return Stud;
}
public void setStud(int stud)
{
Stud = stud;
}
public int getQu1()
{
return Qu1;
}
public void setQu1(int qu1)
{
Qu1 = qu1;
}
public int getQu2()
{
return Qu2;
}
public void setQu2(int qu2)
{
Qu2 = qu2;
}
public int getQu3()
{
return Qu3;
}
public void setQu3(int qu3)
{
Qu3 = qu3;
}
public int getQu4()
{
return Qu4;
}
public void setQu4(int qu4)
{
Qu4 = qu4;
}
public int getQu5()
{
return Qu5;
}
public void setQu5(int qu5)
{
Qu5 = qu5;
}

public String toString()
{
return Stud + " " + Qu1 + " " + Qu2 + " " + Qu3 + " " + Qu4 + " " + Qu5;
}
}

// StudentTest.java
import java.io.*;
public class StudentTest
{
public static final long serialVersionUID = 42L;
public static void main(String[] args) throws IOException,
ClassNotFoundException
{
Student[] students = new Student[15];
students[0] = new Student(1234, 52, 7, 100, 78, 34);
students[1] = new Student(2134, 90, 36, 90, 77, 30);
students[2] = new Student(3124, 100, 45, 20, 90, 70);
students[3] = new Student(4532, 11, 17, 81, 32, 77);
students[4] = new Student(5678, 20, 12, 45, 78, 34);
students[5] = new Student(6134, 34, 80, 55, 78, 45);
students[6] = new Student(7874, 60, 100, 56, 78, 78);
students[7] = new Student(8026, 70, 10, 66, 78, 56);
students[8] = new Student(9893, 34, 9, 77, 78, 20);
students[9] = new Student(1947, 45, 40, 88, 78, 55);
students[10] = new Student(2877, 55, 50, 99, 78, 80);
students[11] = new Student(3189, 22, 70, 100, 78, 77);
students[12] = new Student(4602, 89, 50, 91, 78, 60);
students[13] = new Student(5405, 11, 11, 0, 78, 10);
students[14] = new Student(6999, 0, 98, 89, 78, 20);
FileOutputStream fos = new FileOutputStream("scores.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
for(int i = 0; i < students.length; i++)
{
oos.writeObject(students[i]);
}
oos.close();
fos.close();
int count = 0;
int max1 = 0, min1 = 0; double sum1 = 0;
int max2 = 0, min2 = 0; double sum2 = 0;
int max3 = 0, min3 = 0; double sum3 = 0;
int max4 = 0, min4 = 0; double sum4 = 0;
int max5 = 0, min5 = 0; double sum5 = 0;

FileInputStream fis = new FileInputStream("scores.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
while(true)
{
try
{
Student st = (Student)ois.readObject();
count++;

if(count == 1)
{
max1 = st.getQu1();
min1 = st.getQu1();

max2 = st.getQu2();
min2 = st.getQu2();

max3 = st.getQu3();
min3 = st.getQu3();

max4 = st.getQu4();
min4 = st.getQu4();

max5 = st.getQu5();
min5 = st.getQu5();
}
else
{
if(st.getQu1() > max1)
max1 = st.getQu1();

if(st.getQu2() > max2)
max2 = st.getQu2();

if(st.getQu3() > max3)
max3 = st.getQu3();

if(st.getQu4() > max4)
max4 = st.getQu4();

if(st.getQu5() > max5)
max5 = st.getQu5();

if(st.getQu1() < min1)
min1 = st.getQu1();

if(st.getQu2() < min2)
min2 = st.getQu2();

if(st.getQu3() < min3)
min3 = st.getQu3();

if(st.getQu4() < min4)
min4 = st.getQu4();

if(st.getQu5() < min5)
min5 = st.getQu5();
}

sum1 += st.getQu1();
sum2 += st.getQu2();
sum3 += st.getQu3();
sum4 += st.getQu4();
sum5 += st.getQu5();
}
catch(EOFException e)
{
break;
}
}
ois.close();
fis.close();

System.out.printf("%-12s%6d%6d%6d%6d%6d\n", "High Score", max1, max2, max3, max4, max5);
System.out.printf("%-12s%6d%6d%6d%6d%6d\n", "Low Score", min1, min2, min3, min5, min5);
System.out.printf("%-12s%6.1f%6.1f%6.1f%6.1f%6.1f\n", "Average", sum1/count, sum2/count, sum3/count, sum4/count, sum5/count);
}
}

Tutor Answer

wolfram777
School: Boston College

Hello,Here'e the complete work.I'v tested...

flag Report DMCA
Review

Anonymous
Wow this is really good.... didn't expect it. Sweet!!!!

Similar Questions
Hot Questions
Related Tags

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors