Question: write a method readMarksData() that has a String parameter that allows the name of the data file to be passed to the method. Assuming you
write a method readMarksData() that has a String parameter that allows the name of the data file to be passed to the method.
- Assuming you have set up a suitable Scanner object, you firstly need to read the name of the cohort and the number of marks per student before entering a loop that reads in the data for each student. At this stage, read a set of marks such as 65 60 52 as a single string: do not attempt to read it as three ints, base your code on the following pseudocode
read name of cohort as a string
read number of marks as an int
while there is more data to read
read student name as a string
read marks as a string
To make sure that the data is being read correctly, add println() statements such as System.out.println("student name " + name) to print out each piece of data immediately after you have read it in.
- now read each student's marks "properly" as ints and store them in an array. You will also need to amend your diagnostic println statement(s) for outputting the marks to verify that they have been read correctly and stored in an array.
- Finally, for Step 1:
- comment out the diagnostic println() statements;
- write a private method storeStudentRecord() to add each student's data to marksList;
- write a displayResults() method which will write a report, to the terminal window, on the student's results in a format similar to the one below:
Results for C1
Name Marks
1 Andreas Antoni 65 85 77
2 Charlotte Brockle 87 93 81
3 suzanne dawn 0 55 42
Create a Test class in the project to make testing easier and quicker.
Step 2: Compute each student's average mark
Amend the displayResults() method so that the average mark of each student is calculated so that the output now is similar to:
Results for CS1
Name Marks Average
Andreas Antoniades 65 85 77 75.66666666666667
Charlotte Brocklebank 87 93 81 87.0
suzanne dawson 0 55 42 32.333333333333336
...
Step 3: Add more methods to the MarksProcessor class,
- Write a method writeMarksData() that writes the data for all the student records stored in marksList to a text file in the same format as the files that are used for reading in data
- Write a method clearMarksData() that removes all the entries from marksList. This will be convenient when the user wishes to read in and display a different set of student data.
- Write a method editMarksData() that allows a user to modify the marks of a particular student. The method should have three int parameters:
- studentPosn -- the position of the student as displayed by the displayResults() method;
- markPosn -- the position of the mark to be modified, with 1 for the first mark displayed, etc;
- newMark -- the new mark for the student.
Ive been able to write codes up till the point of writing a private method, im struggling with saving the array of marks into my Arraylist and carrying on, please help
MarksProcessor-HWS Class Edit Tools Options CompileUndo Cut Copy || Paste | | Find- 11 Cose ar int mark3 = scanner.next Int(); moduleMark[0] = mark; moduleMark[1] mark2; moduleMark [2]-mark3; //System.out.println("Client name: + name lastName //System.out.println("Client scores moduleMark le]+ 45 48 49 58 51 52 53 54 scanner.close) At * An example of a method replace this comment with your own 58 59 60 61 62 eparam y a sample parameter for a method * ereturn the sum of x and y private void storeStudentRecords (String fileName) File dataFile = new File(fileName); Scanner scanner new Scanner (dataFile); marksList = new ArrayListStudentRecordsx(); markslist.addA11 (dataFile.readMarksData()); 65 616 MarksProcessor-HWS Class Edit Tools Options CompileUndo Cut Copy || Paste | | Find- 11 Cose ar int mark3 = scanner.next Int(); moduleMark[0] = mark; moduleMark[1] mark2; moduleMark [2]-mark3; //System.out.println("Client name: + name lastName //System.out.println("Client scores moduleMark le]+ 45 48 49 58 51 52 53 54 scanner.close) At * An example of a method replace this comment with your own 58 59 60 61 62 eparam y a sample parameter for a method * ereturn the sum of x and y private void storeStudentRecords (String fileName) File dataFile = new File(fileName); Scanner scanner new Scanner (dataFile); marksList = new ArrayListStudentRecordsx(); markslist.addA11 (dataFile.readMarksData()); 65 616
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
