Hello all. This is my 1st post and I want to thank everyone in advance for any help that you can give me. 1st off this programming this is already not for me, but here is my question. I have to write a program that reads a students name together with his or her test scores. The program should then compute the average test score for each student and assign the app. letter grade. This is what my input looks like: Balto85 83 77 91 76 Mickey80 90 95 93 48 Minnie78 81 11 90 73 Doc92 83 30 69 87 Goofy23 45 96 38 59 Duckey60 85 45 39 67 Grumpy27 31 52 74 83 Sunny93 94 89 77 97 Piggy79 85 2893 82 Pluto85 72 49 75 63
I am having a problem with the loop. I am lost. I can get the output for the 1st student, but that is where it ends. I also need to give a class average, but I didn't even get that far yet. Can someone please help. Here is what I have so far:
The basic issue is that you need to put everything from st = new StringTokenizer (inFile.readLine()); to outFile.println(); in a loop
I would make it a while loop.
SCJP 1.4, SCWCD in process
Joined: Nov 27, 2004
Thank you for all of your help. I put all of that stuff in, but now my problem is that I am only outputting the even number of names. I have 10 input names and the output file is only containing names 2,4,6,8, and 10??? Any thoughts??? Thanks again for the help!!!
NameTest1Test2Test3Test4Test5Average Grade Mickey 80.090.095.093.048.081.20 B Doc 92.083.030.069.087.072.20 C Duckey 60.085.045.039.067.059.20 F Sunny 93.094.089.077.097.090.00 A Pluto 85.072.049.075.063.068.80 D
please use the "code" tags when you post your source - it will preserve the indenting. there's a button below the "add reply" button that will pop then into your post, then just paste your formatted code between them.
Now, as to only outputting the even numbered lines... here's an abrideged version of your code:
do you see how within this single loop, you are calling readLine twice? once line is being fed to the tokenizer, and the next line is being given to myLine. i'm guessing you probably want to take out the line i marked with "this one", but i haven't really dug into your code too much...
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
To help find the problem, you should step through the program by hand. You can make a table of the variables in your program and pretend like you are the computer, stepping through the program one line at a time. Any time the value of a variable changes, write down the new value in the table and cross out its old value. This process should give you an idea of where the problems in your program are.
Also, you can add System.out.println() commands to your program to print out the values of the variable at crucial parts of the code. You can double-check to make sure these values are the same as the ones you calculated by hand.
If you're in JDK 5 take a look at Scanner. There are some cool options to pull numbers and strings out of a stream. It would be interesting to see an instructor's reaction ... if he's expecting you to write this the hard way and you find something in the JDK to do all the work, are you clever or lazy?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi