Chat with us, powered by LiveChat A java program rewrite with solution | WriteDemy

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%6dn", "High Score", max1, max2, max3, max4, max5);
System.out.printf("%-12s%6d%6d%6d%6d%6dn", "Low Score", min1, min2, min3, min5, min5);
System.out.printf("%-12s%6.1f%6.1f%6.1f%6.1f%6.1fn", "Average", sum1/count, sum2/count, sum3/count, sum4/count, sum5/count);
}
}

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Place Order” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order