Jackson Lawton wrote:but don't ask me what I did
Joel Christophel wrote:Could you post the text file?
Joel Christophel wrote:Change this line:
scoreSheet[player][hole] += Integer.parseInt(scoresForOneHole[player]);
To this:
scoreSheet[player][hole] += Integer.parseInt(scoresForOneHole[player].trim());
There were extra spaces after your last column of scores, throwing a runtime exception when you tried to parse them as ints.
Now, to print out the total score at the bottom of each column, add the following to the end of your main method:
Jackson Lawton wrote:
Thanks so much but how do you then get it to show who the winner is???
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:Here is my advice.
delete every line of code you have.
what you have done is called 'programming by accident'. You wrote something, saw it didn't work, tried something else, and repeated until it sort of, kind of, did what you want. That is the worst way to code. You will never, ever, be able to write anything remotely complicated that way.
The proper way is to turn off you computer. Start by THINKING about the problem. Think about it in English. Literally, write down what the steps that YOU would do if you had to solve this by hand - no computer, no variables, no 'for-loops' - just paper, pencil, and erasers.
THAT is the correct way to program.
Jackson Lawton wrote:You're absolutly right, but what if you don't even know where to start and you have a program to create for school??? Sometimes it is better to look through-out your book, try there examples and work them out to fit your situation as that way you're putting to practice what the book is teaching you and it makes your work go much faster, especially when you have 10 programs or more to write. Sitting down and over thinking about the problem that you may not understand would create more time spent on that problem and with working 35 hours a week and 4 nights of school on top of that, it doesn't work out well. Maybe if you are programming as a professional or a hobbiest, or you aren't working and going to school both full-time, that makes total sense. I do agree that's the better way to go but time is so precious to me right now that this is the best way to get my assignments done on time.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Fred is absolutely right. Also, your guessing technique will produce messy‑looking code which will gain you few marks.Jackson Lawton wrote: . . . time is so precious to me right now that this is the best way to get my assignments done on time.
Don't get me started about those stupid light bulbs. |