Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a Java Programming Assignment. ============================================================================================ ============================================================================================ What I need to do - Assignment 7: This assignment is built on top of Assignment 6.

This is a Java Programming Assignment.

============================================================================================

============================================================================================

What I need to do - Assignment 7:

This assignment is built on top of Assignment 6.

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.

============================================================================================

============================================================================================

Following is my Assignment 6 code:

//Driver.java

package driver;

import model.Statistics;

import model.Student;

import Util.FileIO;

import Util.RCOutline;

import Util.Serialization;

public class Driver extends RCOutline{

public static final boolean DEBUG_MODE = true;

public static void main(String[] args) {

Student s[] = new Student[40];

s = FileIO.readFile("quiz.txt", s);

Statistics statPoints = new Statistics();

statPoints.findLow(s);

statPoints.findHigh(s);

statPoints.findAvg(s);

statPoints.printLowScores();

statPoints.printHighScores();

statPoints.printAvgScores();

for (int i = 0; i

s[i].setClassStats(statPoints);

Serialization.serialize(new String("Student")+((Integer)i).toString()+new String (".stu"), s[i]);

}

if(DEBUG_MODE)

{

}

}

}

---------------------------------------------------------------------------------------------------------

//Student.java

package model;

import java.io.Serializable;

public class Student extends ReportCard implements Serializable {

/**

*

*/

private static final long serialVersionUID = 1L;

private int SID;

protected int scores[] = new int[5];

private Statistics classStats;

// Defalut constructor

public Student() {

}

/* Public get and set methods for SID and scores */

@Override

public int getSID() {

return SID;

}

@Override

public void setSID(int SID) {

this.SID = SID;

}

@Override

public int[] getScores() {

return scores;

}

@Override

public int getScore(int index) {

return scores[index];

}

@Override

public void setScores(int[] scores) {

this.scores = scores;

}

@Override

public void setScore(int scores, int index) {

this.scores[index] = scores;

}

@Override

public Statistics getClassStats() {

return classStats;

}

@Override

public void setClassStats(Statistics classStats) {

this.classStats = classStats;

}

// add methods to print values of instance variables.

public void printScores() {

System.out.printf("------- Quiz Scores -------%n");

for (int i = 0; i

System.out.printf("Quiz %d: %d %n", i + 1, scores[i]);

}

System.out.printf("--- - End Quiz Scores ----- %n");

}

public void printStudentID() {

System.out.printf("Student ID: %d %n", SID);

}

@Override

public void printscores(int id) {

// TODO Auto-generated method stub

}

@Override

public void printstats() {

// TODO Auto-generated method stub

}

@Override

void findLow(Student[] studs) {

// TODO Auto-generated method stub

}

@Override

void findHigh(Student[] studs) {

// TODO Auto-generated method stub

}

@Override

void findAvg(Student[] studs) {

// TODO Auto-generated method stub

}

-----------------------------------------------------------------------------------------------

//Statistics.java

package model;

import java.io.Serializable;

public class Statistics extends ReportCard implements Serializable{

/**

*

*/

private static final long serialVersionUID = 1L;

private int[] lowScores = new int[5];

private int[] highScores = new int[5];

private float[] avgScores = new float[5];

/* This method will find the lowest score. */

@Override

public void findLow(Student[] studs) {

for (int i = 0; i

int current = 919;

for (int j = 0; j

if (studs[j].getScore(i)

current = studs[j].getScore(i);

}

}

lowScores[i] = current;

}

}

/* This method will find the highest score. */

@Override

public void findHigh(Student[] studs) {

for (int i = 0; i

int current = -99;

for (int j = 0; j

if (studs[j].getScore(i) > current) {

current = studs[j].getScore(i);

}

}

highScores[i] = current;

}

}

/* This method will find avg score for each quiz. */

@Override

public void findAvg(Student[] studs) {

for (int i = 0; i

float total = 0;

for (int j = 0; j

total += studs[j].getScore(i);

}

avgScores[i] = total / studs.length;

}

}

public void printHighScores() {

System.out.printf("------- High Scores ------- %n");

for (int i = 0; i

System.out.printf("Quiz %d: %d %n", i + 1, highScores[i]);

}

System.out.printf("----- End High Scores ----- %n");

}

public void printLowScores() {

System.out.printf("------- Low Scores ------- %n");

for (int i = 0; i

System.out.printf("Quiz %d: %d %n", i + 1, lowScores[i]);

}

System.out.printf("----- End Low Scores ----- %n");

}

public void printAvgScores() {

System.out.printf("----- Average Scores ----- %n");

for (int i = 0; i

System.out.printf("Quiz %d: %f %n", i + 1, avgScores[i]);

}

System.out.printf("--- End Average Scores --- %n");

}

@Override

public void printscores(int id) {

// TODO Auto-generated method stub

}

@Override

public void printstats() {

// TODO Auto-generated method stub

}

@Override

int getSID() {

// TODO Auto-generated method stub

return 0;

}

@Override

void setSID(int SID) {

// TODO Auto-generated method stub

}

@Override

int[] getScores() {

// TODO Auto-generated method stub

return null;

}

@Override

int getScore(int index) {

// TODO Auto-generated method stub

return 0;

}

@Override

void setScores(int[] scores) {

// TODO Auto-generated method stub

}

@Override

void setScore(int scores, int index) {

// TODO Auto-generated method stub

}

@Override

void printScores() {

// TODO Auto-generated method stub

}

@Override

Statistics getClassStats() {

// TODO Auto-generated method stub

return null;

}

@Override

void setClassStats(Statistics classStats) {

// TODO Auto-generated method stub

}

------------------------------------------------------------------------------------------------

//FileIO.java

package Util;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.StringTokenizer;

import model.Student;

public class FileIO {

public static Student[] readFile(String filename, Student[] stu) {

int studentCounter = -99;

try {

FileReader file = new FileReader(filename);

BufferedReader fileBuff = new BufferedReader(file);

boolean eof = false;

studentCounter = -1;

while (!eof) {

String line = fileBuff.readLine();

if (line == null) {

eof = true;

continue;

}

else if(studentCounter >= 0) {

StringTokenizer st = new StringTokenizer(line);

stu[studentCounter] = new Student();

int quizCounter = -1;

while (st.hasMoreTokens()) {

String currentToken = st.nextToken();

int value = Integer.parseInt(currentToken);

if(quizCounter == -1) {

stu[studentCounter].setSID(value);

}

else {

stu[studentCounter].setScore(value, quizCounter);

}

quizCounter++;

}

}

studentCounter++;

}

fileBuff.close();

} catch (IOException e) {

System.out.println(e.toString());

e.printStackTrace();

}

return trimArray(stu, studentCounter);

}

private static Student[] trimArray(Student[] arr, int count) {

Student[] newArr = new Student[count];

for(int i=0; i

newArr[i] = arr[i];

}

return newArr;

}

}

---------------------------------------------------------------------------------------

//RCOutline.java

package Util;

public abstract class RCOutline implements Reportable {

public void printscores(int id) {

}

public void printstats() {

}

}

-----------------------------------------------------------------------------------------

//Reportable

package Util;

public interface Reportable {

public void printscores(int id);

public void printstats();

public boolean DEBUG = true;

}

--------------------------------------------------------------------------------------------

//Serialization

package Util;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

public class Serialization {

public static boolean serialize(String filename, Object obj) {

try {

ObjectOutputStream serializer = new ObjectOutputStream(new FileOutputStream(filename));

serializer.writeObject(obj);

serializer.close();

if(true) {

System.out.println("Sucess!");

}

}catch (IOException e) {

e.printStackTrace();

return false;

}

return true;

}

public static Object deSerizlize(String filename) {

try {

ObjectInputStream deSerializer = new ObjectInputStream(new FileInputStream(filename));

Object data = deSerializer.readObject();

deSerializer.close();

return data;

}catch (IOException | ClassNotFoundException e) {

e.printStackTrace();

return null;

}

}

================================================================================================

================================================================================================

Some notes that made me confused:

Lab 7

..Requirements for Lab 7 were covered.

..design Presentation on 11/29

Requirements for Gradebook - through interfaces and abstract classes.

Instructor -

Given a text file upload student grades. Modifying (using a new file)

Deliver grades

Query grades for any class

Query grades for any class/student

Compute Grade and Statistics (input a rubric)

Work through the API - instructor interface

..Agile development

....For an instructor - declare an interface with all methods needed for each feature.

....

1. For each interface method - I would implement in an abstract clas - and think about existing methods to integrate for developing the method.

2. If newer classes are needed - then design those in class diagram.

Student -

Query grade for aclass.

View grade progres

Work through the API - student interfaceLab 7

image text in transcribed

My assignment 6 code isn't totally correct.

Here is notes for Assignment 6, I think my class "FileIo" should be "GradeBook".

Review - Lab 6

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. model - ReportCard that contains Stats and Student (make this class abstract) - let it implement Reportable interface. Statistics Student util - FileIO separate serialized file (contains student's score and statistics)

Using debug mode (with Debug flag) print the contents of the serialized file. Create and implement an interface to: Print student statistics. Print scores for a given student id. implement the Debug flag globally Use an abstract class to implement all the methods declared in an interface.Lab 6 -

ReportCard should work with upto 40 students How is ReportCard created? by util - readFile - returns an array of students. Statistics - computes statistics build report card object - in an array - so you can easily serialize each ReportCard - Interface - Reportable public void printscores(int id); public void printstats(); public boolean DEBUG = true; public abstract class RCOutline implements Reportable { public void printscores(int id) { } public void printstats() { } }

public class Driver extends RCOutline { public static void main(String [] args) {

} }

11/20 - If RCOutline is not created and ReportCard becomes abstract - then ReportCard must be extended to be instantiated.

/adapter - Reportable ReportCard Any class that extends ReportCard to instantiate ReportCard

Review - Lab 6 /driver /Driver.java Reportable a1 = new ChildReportCard("35a.txt"); a1.printscore(1221); a1.printscore(1223); a1.printscore(1224); a1.printstats();

..lab 6 review 
public abstract class ScoreReport implements Reportable{ Student s1; Statistics s2; ScoreReport(Student s1, Statistics s2) { this.s1 = s1; this.s2 = s2; } } public class GB extends ScoreReport { Student[] Statistics ScoreReport[] GB(String fname){ //read the file and make student array. //compute statistics //create an array of ScoreReport objects //Serializes each ScoreReport object. } } 

======================================================================================

======================================================================================

What is the previous Assignment Requirement: (You can ignore this)

Assignment 5

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:

Stud Q1 Q2 Q3 Q4 Q5

1234 78 83 87 91 86

2134 67 77 84 82 79

1852 77 89 93 87 71

High Score 78 89 93 91 86

Low Score 67 77 84 82 71

Average 73.4 83.0 88.2 86.6 78.6

The program should print the lowest and highest scores for each quiz.

Plan of Attack

Learning Objectives

You will apply the following topics in this assignment:

File Input operations.

Working and populating an array of objects.

Wrapper Classes.

Object Oriented Design and Programming.

Understanding Requirements

Here is a copy of actual data to be used for input.

Stud Qu1 Qu2 Qu3 Qu4 Qu5

1234 052 007 100 078 034

2134 090 036 090 077 030

3124 100 045 020 090 070

4532 011 017 081 032 077

5678 020 012 045 078 034

6134 034 080 055 078 045

7874 060 100 056 078 078

8026 070 010 066 078 056

9893 034 009 077 078 020

1947 045 040 088 078 055

2877 055 050 099 078 080

3189 022 070 100 078 077

4602 089 050 091 078 060

5405 011 011 000 078 010

6999 000 098 089 078 020

Essentially, you have to do the following:

Read Student data from a text file.

Compute High, Low and Average for each quiz.

Print the Student data and display statistical information like High/Low/Average..

Design

This program can be written in one class. But dividing the code into simple and modular classes based on functionality, is at the heart of Object Oriented Design.

You must learn the concepts covered in the class and find a way to apply.

Please make sure that you put each class in its own .java file.

package lab2;

class Student {

private int SID;

private int scores[] = new int[5];

//write public get and set methods for

//SID and scores

//add methods to print values of instance variables.

}

/************************************************************************************/

package lab2;

class Statistics

{

int [] lowscores = new int [5];

int [] highscores = new int [5];

float [] avgscores = new float [5];

void findlow(Student [] a) {

/* This method will find the lowest score and store it in an array names lowscores. */

}

void findhigh(Student [] a) {

/* This method will find the highest score and store it in an array names highscores. */

}

void findavg(Student [] a) {

/* This method will find avg score for each quiz and store it in an array names avgscores. */

}

//add methods to print values of instance variables.

}

************************************************************************************/

package lab2;

class Util {

Student [] readFile(String filename, Student [] stu) {

//Reads the file and builds student array.

//Open the file using FileReader Object.

//In a loop read a line using readLine method.

//Tokenize each line using StringTokenizer Object

//Each token is converted from String to Integer using parseInt method

//Value is then saved in the right property of Student Object.

}

}

************************************************************************************/

//Putting it together in driver class:

public static void main(String [] args) {

Student lab2 [] = new Student[40];

//Populate the student array

lab2 = Util.readFile("filename.txt", lab2);

Statistics statlab2 = new Statistics();

statlab2.findlow(lab2);

//add calls to findhigh and find average

//Print the data and statistics

}

Topics to Learn

Working with Text Files

//ReadSource.java -- shows how to work with readLine and FileReader

public class ReadSource {

public static void main(String[] arguments) {

try {

FileReader file = new FileReader("ReadSource.java");

BufferedReader buff = new BufferedReader(file);

boolean eof = false;

while (!eof) {

String line = buff.readLine();

if (line == null)

eof = true;

else

System.out.println(line);

}

buff.close();

} catch (IOException e) {

System.out.println("Error -- " + e.toString());

}

}

}

//How do you tokenize a String? You can use other ways of doing this, if you like.

StringTokenizer st = new StringTokenizer("this is a test");

while (st.hasMoreTokens()) {

System.out.println(st.nextToken());

}

//How to convert a String to an Integer

int x = Integer.parseInt(String) ;

Assignment 6

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.

Create and implement an interface to:

1. Print student statistics.

2. Print scores for a given student id.

3. implement the Debug flag globally

Use an abstract class to implement all the methods declared in an interface.

I need this Solution in three hours.

If you can't finish the whole program, please provide the map of package, class, abstract class and interface to me.

Thank you very much!

Miver Statistics 3sa .txt Sodine u Lobs -> Jara ftog Labs stets stics Score Reportir-Reposta bl- ( Subject Grade book -- Studor Reportable tal' = new Grade Book Grado book'); as printGrodest) Rubrie - Oetands | cs .printf(1234) Subject Just Student/ Lab SGrade al - new SGradel); 4 6 . Score report pl] = new Scofereport (40] --> for i : pli] = new Grodeboo (stu til, stat ); Test Sis an interface - Sarade| 1 abstract On Miver Statistics 3sa .txt Sodine u Lobs -> Jara ftog Labs stets stics Score Reportir-Reposta bl- ( Subject Grade book -- Studor Reportable tal' = new Grade Book Grado book'); as printGrodest) Rubrie - Oetands | cs .printf(1234) Subject Just Student/ Lab SGrade al - new SGradel); 4 6 . Score report pl] = new Scofereport (40] --> for i : pli] = new Grodeboo (stu til, stat ); Test Sis an interface - Sarade| 1 abstract On

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_2

Step: 3

blur-text-image_3

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

Students also viewed these Databases questions