All things are lawful, but not all things are profitable.
Knute Snortum wrote:Welcome to the Ranch, Tony Marcello!
generateCourseCounts loops through the StudentCourse collection using the object's courseId getter, and increments the appropriate count in the Map local variable.
generateCourseCounts then uses another local variable, a collection, to sort the counts in order of # Students, decreasing.
generateCourseCounts finally creates the expected output file CourseCounts.csv. This file will be tab-delimited, with a header row. Each line in the file (after the header row) will have two values - the name of the course, and the # students registered for that course.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:
The commented lines use the wrong type of Map and accumulate a List of Students instead of a count.
After you have your Map created, pass it to a method that writes it to a file.
There is a lot more to do, but start with cleaning up generateCourseCounts() to just create the correct Map.
Paul Clapham wrote:You call loadStudentCourses and assign it to a list of StudentCourse objects, but then you subsquently don't use any of those objects. I think that's a significant thing.
Paul Clapham wrote:
This should be implemented as a Map<course, count>. But you haven't quite done that...
Paul Clapham wrote:No.
This doesn't map courses to counts. A count is obviously an integer, but a course isn't an integer.
Paul Clapham wrote:No, you don't want to map lists of courses to integers, you want to map courses to integers. So:
Campbell Ritchie wrote:I think you are putting the cart before the horse.
That's a pleasureTony Marcello wrote:. . . . Thank you ever so much . . . .
Campbell Ritchie wrote: there is a counting exercise in the Javaâ„¢ Tutorials. If you don't understand the explanation, please ask again.
That's a pleasure I trust you understood how it works. Isn't it nice and simple when you see it working.Tony Marcello wrote:. . . cure to my ills. I thank you again! . . .
Campbell Ritchie wrote:Isn't it nice and simple when you see it working.
Campbell Ritchie wrote:Start by defining what the tab separated file (it is akin to a CSV file) will look like. You may have to give your Map a different “K” that will correspond to what you want in the output file.
Campbell Ritchie wrote:
Paul Clapham wrote:I thought it might happen that you needed to write the name of the course to the CSV file output. But is that name not part of the StudentCourse object?
Paul Clapham wrote:I was wondering why the class was named "StudentCourse" and not "Course". So what's in StudentCourse, then?
Paul Clapham wrote:
What you would need to do is, as you're reading the CSV file and creating the Course objects, you'd need to build a Map<Integer, Course> so that given a course ID you could find the Course corresponding to that ID.
For a quick finish after doing that, you could just use that Map to answer the last problem you had
Shiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|