Question

This is a java homework for my java class. Write a program to perform statistical analysis...

This is a java homework for my java class.

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.

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 {

static 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) ;

For now the part that I need help the most is the Util.java class. Here is my code for that class:

public class Util {
   static 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.
       int counter = 0;
       int score = 0;
       int SID = 0;
       try {
           FileReader file = new FileReader("Quiz.txt");
           BufferedReader buff = new BufferedReader(file);
           boolean eof = false;
           while (!eof) {
               String line = buff.readLine();
               counter++;
               if (line == null)
                   eof = true;
               else {
                   if (counter == 1)
                       ;
                   if (counter > 1) {
                       StringTokenizer st = new StringTokenizer(line);
                       while (st.hasMoreTokens()) {
                           Student student = new Student();
                           for (int i = 0; i < 15; i++) {
                                   student.setSID(Integer.parseInt(st.nextToken()));
                               student.setScores(Integer.parseInt(st.nextToken()), 0);
                               student.setScores(Integer.parseInt(st.nextToken()), 1);
                               student.setScores(Integer.parseInt(st.nextToken()), 2);
                               student.setScores(Integer.parseInt(st.nextToken()), 3);
                               student.setScores(Integer.parseInt(st.nextToken()), 4);

                               stu[i] = student;
                           }

                       }
                   }
               }
           }
           buff.close();
       } catch (IOException e) {
           System.out.println("Error -- " + e.toString());
       }

       return stu;
   }
}

It has the following error:

Exception in thread "main" java.util.NoSuchElementException

at java.util.StringTokenizer.nextToken(Unknown Source)

at lab5.Util.readFile(Util.java:34)

at lab5.Driver.main(Driver.java:9)

I want to keep using String tokenizer instead of any other method and the design have to be the same as my professor suggestion. Thank you.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
This is a java homework for my java class. Write a program to perform statistical analysis...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Java programming help My program wont run. could someone tell me why. everything seems correct to...

    Java programming help My program wont run. could someone tell me why. everything seems correct to me... giving me the error: Exception in thread "main" java.lang.NumberFormatException: For input string: "Stud" at java.base/java.lang.NumberFormatException.forInputString(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at Util.readFile(Util.java:35) at Driver.main(Driver.java:8) _________________________________________________________________________________________________________________________ Program Prompt: 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...

  • package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public...

    package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public static void main (String [] args)    {    // ============================================================    // Step 2. Declaring Variables You Need    // These constants are used to define 2D array and loop conditions    final int NUM_ROWS = 4;    final int NUM_COLS = 3;            String filename = "Input.txt";    // A String variable used to save the lines read from input...

  • What is the problem with my Program ? also I need a Jframe that desplays the...

    What is the problem with my Program ? also I need a Jframe that desplays the original input on the left side and the sorted input of the left side. my program is supose to read the number for basketball players, first name, last name, and float number that is less than 0 . on the left sideit is supposed to sort all this input based on last name. This is my demo class : package baseball; import java.io.*; import...

  • Public class File {    public String base; //for example, "log" in "log.txt"  &nbs...

    public class File {    public String base; //for example, "log" in "log.txt"    public String extension; //for example, "txt" in "log.txt"    public int size; //in bytes    public int permissions; //explanation in toString public String getExtension() {        return extension;    } public void setExtension(String e) {           if(e == null || e.length() == 0)            extension = "txt";        else            extension = e;    } public class FileCollection {    private File[] files;    /**    * DO NOT MODIFY    * Loads collection from input file    * @param input: name...

  • I'm working with Java and I have a error message  1 error Error: Could not find or...

    I'm working with Java and I have a error message  1 error Error: Could not find or load main class Flowers. This is the problem: Instructions Make sure the source code file named Flowers.java is open. Declare the variables you will need. Write the Java statements that will open the input file, flowers.dat, for reading. Write a while loop to read the input until EOF is reached. In the body of the loop, print the name of each flower and where...

  • In java write a simple 1-room chat server that is compatible with the given client code.

    In java write a simple 1-room chat server that is compatible with the given client code. 9 public class Client private static String addr; private static int port; private static String username; 14 private static iter> currenthriter new AtomicReference>(null); public static void main(String[] args) throws Exception [ addr -args[]; port Integer.parseInt (args[1]); username-args[21 Thread keyboardHandler new Thread(Main: handlekeyboardInput); 18 19 while (true) [ try (Socket socket -new Socket (addr, port) println(" CONNECTED!; Printwriter writer new Printwriter(socket.getoutputStreamO); writer.println(username); writer.flush); currenthriter.set(writer); BufferedReader...

  • Input hello, I need help completing my assignment for java,Use the following test data for input...

    Input hello, I need help completing my assignment for java,Use the following test data for input and fill in missing code, and please screenshot output. 1, John Adam, 3, 93, 91, 100, Letter 2, Raymond Woo, 3, 65, 68, 63, Letter 3, Rick Smith, 3, 50, 58, 53, Letter 4, Ray Bartlett, 3, 62, 64, 69, Letter 5, Mary Russell, 3, 93, 90, 98, Letter 6, Andy Wong, 3, 89,88,84, Letter 7, Jay Russell, 3, 71,73,78, Letter 8, Jimmie Wong,...

  • I have my assignment printing, but I can find why the flowers is printing null and...

    I have my assignment printing, but I can find why the flowers is printing null and not the type of flower. Instructions Make sure the source code file named Flowers.java is open. Declare the variables you will need. Write the Java statements that will open the input file, flowers.dat, for reading. Write a while loop to read the input until EOF is reached. In the body of the loop, print the name of each flower and where it can be...

  • Help !! I need help with Depth-First Search using an undirected graph. Write a program, IN JAVA, ...

    Help !! I need help with Depth-First Search using an undirected graph. Write a program, IN JAVA, to implement the depth-first search algorithm using the pseudocode given. Write a driver program, which reads input file mediumG.txt as an undirected graph and runs the depth-first search algorithm to find paths to all the other vertices considering 0 as the source. This driver program should display the paths in the following manner: 0 to ‘v’: list of all the vertices traversed to...

  • Please correct the comments on the java program below jtxtRanking.setText("Invalid marks"); JOptionPane.showMessageDialog(null, "Marks should be between 0-100", "Error", JOptio...

    Please correct the comments on the java program below jtxtRanking.setText("Invalid marks"); JOptionPane.showMessageDialog(null, "Marks should be between 0-100", "Error", JOptionPane.ERROR_MESSAGE); System.exit(0); }    //The DefaultTableModel can be acessed through the getModel method DefaultTableModel model = (DefaultTableModel) jTable.getModel();    //Add a row model.addRow(new Object []{    // receive datas from the following and display it on the table jtxtStudentID.getText(), jcmbCourseCode.getSelectedItem(), jtxtAverage.getText(), jtxtRanking.getText(),    }); try { FileReader fr = new FileReader(file); // read data from the file BufferedReader br = new BufferedReader(fr); // instantiate BufferedReader object   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT