• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program to read in text file of ID's and answers and grade them then display, how do i fix it?  RSS feed

 
Alex Breault
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex, welcome to the Ranch!

The answer to your question "How do I fix it?" at this point is "I dunno, what's wrong with it?"

In other words it would be very helpful if your post would explain the problem. For more about how to explain problems, you could start with our FAQ entry ItDoesntWorkIsUseless (<-- click that link) and then let's take it from there.
 
Alex Breault
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to grade the quiz by counting up each time the two arrays match with totalCorrect and it always is 0
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex Breault wrote:I am trying to grade the quiz by counting up each time the two arrays match with totalCorrect and it always is 0


Really? I found some code which uses a variable named "totalCorrect" but there's only one array in that part of the code. However there's over 300 lines of code there so I might well have missed something else while scrolling up and down looking at the code. You could have spent another few seconds and told us which part of the code you were asking about.

I have to admit that what you do with the totalCorrect variable is kind of strange, but saying that it is always zero can't be true since you initialize it to 10. Or perhaps the "it" which is always zero is something else, and I just incorrectly assumed you were referring to totalCorrect.

It would really be better if you gave us a more detailed explanation of your problem.
 
Alex Breault
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


when i put the value of 10 to it, that was a test to see if it would return as the same value of 10 or what would happen to it
I just really don't know why totalCorrect is not changing
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some strange things in that code which I don't quite understand. But let's pass over them for now and just ask, what makes you think that "totalCorrect" isn't changing?

And also are you referring to the totalCorrect variable in that gradeQuiz method, or the totalCorrect variable in the code which calls it?
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are also some simple things in that code which I do understand. I know you are told to write comments to explain the code, but after writing
FileReader fileReader = new FileReader(file);
it is completely unnecessary to say you have created a file reader object. you should remove that sort of comment.
Unfortunately in the same method, you appear not to use that file reader to read anything, so why have you got it? It does nothing to prevent you using non‑existent files.
 
Liutauras Vilda
Sheriff
Posts: 4927
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know which methods are working as expected and which causing you issues?
See what I'm trying to say? It appears you wrote all those > 300 lines of code without any testing of it.

Those comments which are meant to be JavaDoc's these are not, as you use incorrect JavaDoc comments syntax. But that is not the biggest issue you are facing now.

Please tell us what this your method below does (I fixed indentation):

Probably the best approach would be to start over. I am sorry.
 
Liutauras Vilda
Sheriff
Posts: 4927
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a positive side, you know Java syntax as you wrote quite a lot code already. The problem it seems you're facing currently is - lack of testing before you move onto another task.

Keep this code as a reference, some of the parts you'll be able to to re-use probably. Some of them are just wrong, so no harm to delete.

I hope you're clear with your requirements of program and have read them three times at least to make sure you understand them well.
If you haven't:

1. Read requirements once again, only the very first task (omit the rest, these not needed now as it is not a complex system)
2. Create new .java file
3. Define class name, not Proj5 - that could be in the general comment of the class if it needs to be mentioned somewhere. Consider naming it GradeSystem or similar.
4. Create main method and populate with 1 line of code. i.e.:
5. Create method which takes user input, NOW you use some of your code from your previously written code, see code below, make it a method:
and it would look like
later you'll be able to call that method and test it if it works as expected:
Quickest way to test it, is to run that program, input number 4 and print that out, with:

6. So, ONLY when you're sure about the correctness of the present code, you move forward. For your reference what the code looks like at that time:

And you do all the same with the rest of your program. Write 1 method (3 lines of code - compile - 3 lines of code - compile), test it. Move onto the next task.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!