• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassGrader using arrays

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am taking an online class and the projects went from easy to difficult real fast. Now i think I just don't understand the material enough to program this project.
The program takes a .txt file and changes it into a .csv in excel. Takes the names and grades in the file to match up with a name, midterm, project, final test, and average of the grades section above.
There are three classes , a Finalproject, Student and Grade.

Here is what my teacher said to do for the part I am stuck on:

The grades[] array in the Student class is made up of Grade objects, not int primitives.
The format of the input file is exactly the same as the ClassGrader project, i.e., there are 3 lines of grade information after the student name, so setGradesFromFile (method of the Student object just created from the line of text with the name) should be reading those 3 lines, only, and putting the result of each line into grades[].
Then you need to read 3 lines in the file, i.e., in a loop (for (int i = 0; i < 3; i++)). If you do not use a loop, you would need to repeat that code you have 3 times (plus another step).
Use the int grade value you have to create (i.e., new) a Grade object, and use the loop index to put that object into the grades array.

My attempt on the Student Class:



I have no clue what I am doing for the setGradesFromFile method.
 
Bartender
Posts: 242
27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, my understanding is that you need to read three lines from a file and put them into a Grade array?

You have a Scanner that is (presumably) initialized to the text file, so all you should need to do is call the nextLine() method on that scanner to read a line from the file. After reading the line, you can create a new Grade object (you should have some constructor that takes a String in Grade) and put it into the array. You don't really need a loop for 3 lines of code, but that can work too, I guess.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Maybe a loop is the right thing to use, even for three lines, but are you sure you have three lines? To avoid any risk of errors, use a while loop and use one of the hasNextXXX methods of the Scanner. You should not rely on a number literal because it is error‑prone.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wrote:

The outer parentheses are not needed. You probably got this from the written instructions.
 
You don't like waffles? Well, do you like this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic