Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment is built on top of Assignment 2. Add capability to handle Grade Book for different subjects (Chemistry and Computer Science). We will assume

This assignment is built on top of Assignment 2.

Add capability to handle Grade Book for different subjects (Chemistry and Computer Science).

We will assume a maximum of five assignments and up to 40 students.

Details will be provided in the class.

This is my code from assignment 2:

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago

Question

LO5 Illustrate the steps in developing a base pay system.

Answered: 1 week ago

Question

LO3 Outline strategic compensation decisions.

Answered: 1 week ago