Reading csv file
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have an assignment to read student grades from a csv file. Each represents a result a certain student obtained for a certain course.
A student can appear on several lines, since he/she has taken a number of courses.
The Student class constructor looks like this
So a student has a list of results.
For the readCsv () function my guess would be to make a list of maps. The student being the key and the result arraylist as the value(s).
I keep getting on an error on the way the studentlist is composed.
Would it be better to just store in a list of strings and then use separate logic to get the results student by student ?
How would I be able to recognize identical students ? Surname and name are in different columns.
Thanks in advance.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
In most real‑life applications one wouldn't read a CSV directly, but use a program designed to cope with CSVs. Obviously your assignment forces you to read the file “by hand”. How you do that depends on the format of the file and what delimiters you are using.
I would suggest you initialise the List in the constructor. You cannot be sure that a setXXX() method will ever be called and your object will be created in an inconsistent state. I would also have used a Scanner to parse the lines. Depending on the delimiter, you can use the Scanner object to read the whole file or read each line separately.You don't need the counter. If you have a line with headers in, you can simply read one line before the start of the loop. You don't need the arrays; add the elements to the List directly.
Your Student object should take a defensive copy of the List, otherwise it is possible for its state to be changed by outside code without your knowing about it. Strings, being immutable, do not need to be copied.
Why have you got all those setXXX() methods? I know many people think they are an essential part of a class, but that isn't a part of the general tenets of object‑orientation. There are great advantages to making an object immutable.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
welcome to the Ranch and enjoy the stay!
Your studentList is a List of Maps, so
will not work. Instead, you should do something like:
or
But a Student already has a field results. being a List<Result>. So why create that Map<Student, ArrayList<Result> ?
Edit: I am a bit confused about Result and an ArrayList<Result>. What does a Result represent?
There are three kinds of actuaries: those who can count, and those who can't.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The csv is in the following format :
email surname name course grade type Weight Period
[email protected]Jef Daniels Operating Systems 16.33 PartialEvaluation 1 25% november
[email protected]Jef Daniels Hardware xx PartialEvaluation 1 50% november
[email protected]Jef Daniels Databank 9.0 PartialEvaluation 1 50% november
[email protected]Kenny Rogers Hardware 8.66 PartialEvaluation 1 50% november
[email protected]Kenny Rogers Operating Systems 12.33 PartialEvaluation 1 25% november
[email protected]Kenny Rogers OO Concepts 7.00 PartialEvaluation 1 30% november
[email protected]Greta Thunberg OO Concepts 11.00 PartialEvaluation 1 30% november
[email protected]Greta Thunberg Hardware 15.33 PartialEvaluation 1 50% november
[email protected]Greta Thunberg Operating Systems 17.33 PartialEvaluation 1 25% november
The goal not to just show information, an assessment needs to be made if a student for example fails at more then 4 courses, he receives an email with a certain message, same goes for passing 3 or more courses etc. all with different types of feedback emails.
So in my view for a student object needs to have a set of results in order to evaluate him. I think I just best look into openCsv or Apache csv.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
That's a pleasureAndreas Loon wrote:. . . thanks . . .

That isn't a CSV file. It is tab‑separated, which is rather similar to CSV. You can parse it with "\\t" as a delimiter, but that probably won't pick up “november” which is terminated by a line end. You can correct that with a combination of reading lines and reading individual tokens later.The csv is in the following format :
email surname name course grade type Weight Period
[email protected]Jef Daniels Operating Systems 16.33 PartialEvaluation 1 25% november
[email protected]Jef Daniels Hardware xx PartialEvaluation 1 50% november
[email protected]Jef Daniels Databank 9.0 PartialEvaluation 1 50% november
[email protected]Kenny Rogers Hardware 8.66 PartialEvaluation 1 50% november
[email protected]Kenny Rogers Operating Systems 12.33 PartialEvaluation 1 25% november
[email protected]Kenny Rogers OO Concepts 7.00 PartialEvaluation 1 30% november
[email protected]Greta Thunberg OO Concepts 11.00 PartialEvaluation 1 30% november
[email protected]Greta Thunberg Hardware 15.33 PartialEvaluation 1 50% november
[email protected]Greta Thunberg Operating Systems 17.33 PartialEvaluation 1 25% november
. . .
You will have to find some way to convert 25% to 0.25.
You have got name and surname in the wrong order.
You will have to find some way to record some sort of ID (maybe using email as a key) against the Student object. Maybe methods like Map#putIfAbsent() wll be useful there. You will then need a method to add a score. The scores ending ….33 and ….66 won't add up correctly.
You will fail to read Jef Daniels' second line because of the, “xx.” If I found that in a file, I would return the file to its creator as “format corrupted”.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
and you can retrieve information for example:
There are three kinds of actuaries: those who can count, and those who can't.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
To deal with the results, I created the following Result class
The getter to retrieve grades
To get overall results a separate PeriodResult class is made with an enum to indicate the colour code depending on the amount of failed or passed courses
The main method
As a final result I need to make a GUI to load and represent the data and send emails to the students.
My idea of the gui was the attached setup. Fxml is not allowed, the idea was to implement it as a tableview.
How would I load the csv read data into a tableview ?
| Maybe he went home and went to bed. And took this tiny ad with him: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






