Question: JAVA: The project is to keep records and perform analysis for a CSC 20 class of students. Our Spring 2018 CSC 20 lab may have
JAVA:
The project is to keep records and perform analysis for a CSC 20 class of students. Our Spring 2018 CSC 20 lab may have up to 17 students. However, please make a note that
this number can be changed since there are more students to be added to the course. There are five labs (assumed we have five) during the section. Each student is identified by a four-digit student ID number. 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. 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
NOTE: 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
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.
Put each class in its own .java file.
Code Snippets: The following code is only one of the design. .
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:
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 stri
ng 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
Get step-by-step solutions from verified subject matter experts
