• Post Reply Bookmark Topic Watch Topic
  • New Topic

reassigning grade based on highest grade  RSS feed

 
bryan sanchez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get a list of number from a text file and then reassign the the grades based on the highest number in the list, i am having trouble as my code is not working correctly, any help would be appreciated, thanks in advance
Grade is A if score >= best - 10;
Grade is B if score >= best - 20;
Grade is C if score >= best - 30;
Grade is D if score >= best - 40;
Grade is F otherwise
the logic seems to not be correct, so say my list contains number
3
4
5
it prints
Student 1 score is 3 and grade is A
Student 2 score is 3 and grade is A
Student 3 score is 3 and grade is A
Student 1 score is 4 and grade is A
Student 2 score is 4 and grade is A
Student 3 score is 4 and grade is A
Student 4 score is 4 and grade is A
Student 1 score is 5 and grade is A
Student 2 score is 5 and grade is A
Student 3 score is 5 and grade is A
Student 4 score is 5 and grade is A
Student 5 score is 5 and grade is A
so basically its repeating the grades into the student variable as well, i am very new to arrays so it is confusing

it should print out something like this
Student 1 score is 3 and grade is C
Student 2 score is 4 and grade is B
Student 3 score is 5 and grade is A
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you done any debugging to find out what the values of bestscore and so on are, when you're doing the comparisons which don't work out the way you expected?
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You cannot solve that sort of problem with code; you have to work it out with a pencil and paper beforehand. Please explain in words of one syllable, simply enough for me to understand, what you are trying to do.

You have some stylistic problems in your code, I am afraid. Avoid UPPER-CASE throughout, especially for class names.
Avoid System.exit. It can be too vicious and abrupt in stopping execution.
Always put {} after if while etc. You can confuse yourself seriously with things like in lines 62-81.
Don't double‑space code; that makes it harder to read.
You have a design problem that you have much too much code in the main method. That code shou‍ld be divided into about 4 methods. That way you don't have the confusing feature of two Scanners running in parallel.
You also don't appear to be closing the file Scanner. You know you mustn't clase the Scanner pointing to System.in.
Why are you reading doubles from the keyboard and converting them to ints for your array indices? Why not simply read ints?
 
Carey Brown
Saloon Keeper
Posts: 3322
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 43 you are assigning 'num' when you should be getting the next input from your file scanner.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!