Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[JAVA] I need help with this assignment since I'm having diffuculty This assignment is built using the code from the previous assignment. Create a separate

[JAVA] I need help with this assignment since I'm having diffuculty

This assignment is built using the code from the previous 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:

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.

Here is what the program needs:

1. Create a new package - adapter 2. Create an interface public interface Studentdata { public final boolean DEBUG = true; public void statistics(); public void printscores(int studentid); } 2b.Create a class called StudentStat and add it in same package as Student and Statistics. public class StudentStat { private Student s1; //holds data for one students. private Statistics stat; //holds statistics for entire class. //write - getter/setter/constructor and print() } 3. create an abstract class. public class MethodImpl implements Studentdata { public MethodImpl() { //Call the method that reads the data from text file into Student [] //Compute stats //Create an array of StudentStat class. (if there are 15 students then the array size will be 15 as well. //Write each StudentStat object to disk. } public void writeStudstat(String studentid) { //This method will serialize the one instance of StudentStat to disk. } public StudentStat readStudentstat(String studentid) { //Should read the contents of serialized file. } //Implement the methods in Studentdata below. public void statistics() { } public void printscores(int studentid) { //read the object from disk - by calling readStudentstat() //and the the print student scores only. } } 4. Create a new class Driver that extends MethodImpl - Create a main in the Driver class that shows the usage of the methods. public class Driver extends MethodImpl { public Driver() { super(); } public static void main(String [] args) { Studentdata test = new Driver(); //why will this work? test.statistics(); test.printscores(1234); //call this multiple times. test.printscores(....); test.printscores(....); } }

__________________________________________________________________________________________________________

Here is my previous assignment:

Driver class

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

package lab;

public class Driver {

public static void main(String[] args) {

//Class has up to 40 students

Student Student[] = new Student[40];

int count=0;

//reads quiz text file

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

count= Util.students;

Statistics s = new Statistics();

System.out.printf("%-7s %-7s %-7s %-7s %-7s %-7s ", "Student", "Quiz1", "Quiz2", "Quiz3", "Quiz4", "Quiz5" );

//for loop for printing individual student results

for(int i = 0; i

{

Student[i].printValues();

}

System.out.println();

//calls on printStatitics for quiz statistics

s.printStatistics(Student,count);

}

}

Util class

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

package lab;

import java.io.*;

import java.util.StringTokenizer;

public class Util {

static int students;

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

{

int i=0;

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

//try catch scenario for reading text file

try {

FileReader file = new FileReader(filename);

BufferedReader buff = new BufferedReader(file);

boolean eof = false;

while (!eof) {

String line = buff.readLine();

if (line == null)

eof = true;

else

{

stu[i]= new Student();

StringTokenizer st = new StringTokenizer(line);

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

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

while(st.hasMoreTokens())

{

//The parseInt() function parses a string argument and returns an integer

//Saved in property of Student

stu[i].setSID(Integer.parseInt(st.nextToken()));

int[] token= new int[5];

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

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

token[j]= Integer.parseInt(st.nextToken());

}

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

stu[i].setScores(token);

}

}

i++;

}

buff.close();

}

catch (Exception e)

{

System.out.printf("No file found ");;

}

students = i-1;

return stu;

}

}

Student Class

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

package lab;

public class Student

{

private int SID;

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

//set method for student id

public void setSID(int id)

{

this.SID= id;

}

//get method for student id

public int getSID(){

return SID;

}

//set method for quiz scores

public void setScores(int[] scores)

{

this.scores= scores;

}

//get method for quiz scores

public int[] getScores()

{

return scores;

}

//add methods to print values of instance variables.

//prints student data from read file

public void printValues()

{

System.out.printf("%-7d %-7d %-7d %-7d %-7d %-7d ",SID, scores[0], scores[1], scores[2], scores[3], scores[4]);

}

}

Statistics class

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

package lab;

public class Statistics {

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

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

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

//Method used for finding high quiz scores

void findHigh(Student[] stud, int count)

{

int i=0;

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

{

int[] hold= stud[0].getScores();

int high = hold[i];

for(int j=0; j< count; j++)

{

int[] s= stud[j].getScores();

if(high < s[i])

{

high = s[i];

}

}

highscores[i]= high;

}

}

//method used for finding low scores

void findLow(Student[] a, int count)

{

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

{

int[] hold= a[0].getScores();

int low = hold[i];

for(int j=0; j< count; j++)

{

int[] s= a[j].getScores();

if(low > s[i])

{

low = s[i];

}

}

lowscores[i]= low;

}

}

//Method used for finding average scores

void findAvg(Student[] a, int count){

int i=0;

//int total = 0;

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

int total=0;

for(int j=0; j

int[] s= a[j].getScores();

total= total + s[i];

}

avgscores[i]= total/count;

}

}

//method for printing scores

public void printStatistics(Student[] stud, int count){

//calls on findlow method to find low scores

findLow(stud,count);

//calls on findhigh method to find high scores

findHigh(stud, count);

//calls on findavg to find all average scores

findAvg(stud, count);

System.out.printf("%-12s %-12s %-12s","High scores", "Low Scores", "Average Scores " );

//for loop for printing out scores

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

{

System.out.printf("%-12d %-12d %-12.1f ", highscores[i], lowscores[i], avgscores[i]);

}

}

}

Edit: Also here is the text file I used:

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

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

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

More Books

Students also viewed these Databases questions

Question

When will I do them?

Answered: 1 week ago