Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program is to output the student scores and calculate and print the statistics for each lab. The output is in the same order as

The program is to output the student scores and calculate and print the statistics for each lab. The output is in the same order as the input; no sorting is needed. The input is to be read from a text file Labs.txt. The output from the program should be similar to the following: Here is some sample data (for illustration only):

Stud L1 L2 L3 L4 L5 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

Use one and two-dimensional arrays only. Test your program with the following data - Program should print all the lowest or highest scores for each lab.

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

Stud L1 L2 L3 L4 L5 1234 032 017 020 028 034 2134 030 036 030 017 030 3124 030 035 020 030 030 4532 031 017 031 032 027 5678 040 012 035 028 034 6134 034 040 035 018 025 7874 030 030 036 038 018 2877 035 030 019 022 030 3189 022 030 020 018 017 4602 039 040 021 038 016 5405 011 011 020 021 010 6999 022 028 029 011 020 8026 040 010 026 028 016 9893 024 009 017 027 020 1947 025 020 028 023 035

These Concepts MAY apply to this project; 1. Object Oriented Programming. 2. File IO. 3. Wrapper Classes.

Essentially you have to do the following: (1) Read Student data from a formatted file. (2) Compute High, Low and Average for each lab score. (3) Print the student data and statistical information. (4) Be able to use abstract class for this program

Designing: Put each class in its own .java file. Code Snippets: The following code is only one of the design. There are other design options.

Assume you declared: final int NUMBER_OF_CSC20_LABS = 5; (note: You might choose to implement this assignment using ArrayList if you wish. This option is a better design since this implementation can work with any number of labs) class Student { private int SID; private int scores[] = new int[NUMBER_OF_CSC20_LABS]; // write public getter and setter methods for // SID and scores // add methods to print values of instance variables. } class Statistics { private int [] lowscores = new int [NUMBER_OF_CSC20_LABS]; private int [] highscores = new int [NUMBER_OF_CSC20_LABS]; private float [] avgscores = new float [NUMBER_OF_CSC20_LABS]; void calculateLow(Student [] a) { // This method will find lowest score and store it in an array names lowscores } void calculateHigh(Student [] a) { // This method will find highest score and store it in an array names highscores } void calculateAvg(Student [] a) { // This method will find avg score for each lab and store it in an array named avgscores } // add methods to print values of instance variables. } class Util { public static Student[] readFile(String fileName) throws IOException { // 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 all together: (in a seperate class) public static void main(String [] args) { Student[] studArr = Util.readFile("studentData.txt"); Statistics stat = new Statistics(); stat.calculateLow(studArr); // add calls for the high and average values // Print the data and statistics, etc. } Additional materials: 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); String line; line = buff.readLine(); while (line != null) { System.out.println(line); line = buff.readLine(); } buff.close(); } catch (IOException e) { System.out.println("Error " + e.toString()); } } } How do you tokenize a String? The following example illustrates how the String.split method can be used to break up a string into its basic tokens: String[] result = "this is a test".split("\\s"); for (int x=0; x System.out.println(result[x]); How to convert a String to an Integer: int x = Integer.parseInt(str);

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 Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago

Question

1. Communicating courses and programs to employees.

Answered: 1 week ago

Question

6. Testing equipment that will be used in instruction.

Answered: 1 week ago