Forums Register Login

reassigning grade based on highest grade

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
On line 43 you are assigning 'num' when you should be getting the next input from your file scanner.
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 307 times.
Similar Threads
Getting the average to display
I think I'm stuck!!
ArrayIndexOutOfBoundsException:4
Actually I'm lost
Writing to a text file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:08:17.