Question
class Student { private int SID; private int scores[] = new int[NUMBER_OF_CSC20_LABS]; // write public getter and setter methods for // SID and scores //
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 string into its basic tokens: String[] result = "this is a test".split("\\s"); for (int x=0; x
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started