I take this back. I misread where the ending paren was.Carey Brown wrote:The result of this expression may be cast as a double but the actual arithmetic will be operated on as ints.
Carey Brown wrote:Note that after your last call to input.nextInt() you'll have to call input.nextLine() to flush out the new-line that will be left over in the input buffer. You can ignore the returned string from this call to nextLine().
Carey Brown wrote:Please repost the entire code and the entire error message.
Carey Brown wrote:Your error message says you are trying to use a file called "name.java". What is this?
Your other java file compiles and runs fine for me.
Carey Brown wrote:Note that after your last call to input.nextInt() you'll have to call input.nextLine() to flush out the new-line that will be left over in the input buffer. You can ignore the returned string from this call to nextLine().
Carey Brown wrote:You're still closing the Scanner.
Carey Brown wrote:When you make changes to the code you need to repost it so that I see what you see.
Scanner is more an "advanced beginner" subject but seeing as how Java doesn't really have good alternatives you will have to pay close attention to whatever advice is given to you regarding Scanners.
Carey Brown wrote:Wrong code again.
Carey Brown wrote:Ah, you moved the loop. I didn't see it.
So you prompt for the grades only once because it is outside the loop. Is this what you want to do?
Consider that lines will be executed in order unless there is a loop to tell it otherwise.
Carey Brown wrote:You should only ever create one instance of a Scanner from System.in, and you should never ever close it, no matter what warning messages say.
Sean Stevens wrote:I'm attempting to set it up so you can input grades for name x, then once the output is displayed it prompts you to input grades for name y and so on.
Carey Brown wrote:
Carey Brown wrote:
Carey Brown wrote:
Take this step by step:
1) all the code required to get the name and nothing more.
2) this "while" statement
3) all your other code except for the "get name" code you used in step 1.
4) repeat the get name code here to get the next name
5) closing brace for while loop.
Carey Brown wrote:Getting closer. Instead of 2nd while repeat lines 19 and 20.
AND REMOVE input.close().
Sean Stevens wrote:
Carey Brown wrote:Getting closer. Instead of 2nd while repeat lines 19 and 20.
AND REMOVE input.close().
lol this is so frustrating. Thank you so much for your help so far by the way. Did as you said and also removed the scanner line you said to. got another error message!
Exception in thread "main" java.lang.IllegalStateException: Scanner closed
Enter Your Name
at java.util.Scanner.ensureOpen(Scanner.java:1070)
at java.util.Scanner.findWithinHorizon(Scanner.java:1670)
at java.util.Scanner.nextLine(Scanner.java:1538)
at Averages5.main(Averages5.java:49)
Sean Stevens wrote:
Did as you said and also removed the scanner line you said to. got another error message!Carey Brown wrote:Getting closer. Instead of 2nd while repeat lines 19 and 20.
AND REMOVE input.close().
Carey Brown wrote:
Sean Stevens wrote:
Did as you said and also removed the scanner line you said to. got another error message!Carey Brown wrote:Getting closer. Instead of 2nd while repeat lines 19 and 20.
AND REMOVE input.close().
No you didn't. It's still there on line 33.
Carey Brown wrote:Here's the change you'll need to flush the pending new-line as I mentioned earlier. Without it it won't process the next name.
We often get students in the Beginner forum so this is sort of expected. Also, as it is the Beginner forum, we try not to just give you the answer but to give you hints and guidance so that you can work out some of this for yourself. I hope that now that it is working that you'll study your code to fully understand how it flows.Sean Stevens wrote:Thank you so much, works fine. I know I just seem like some student looking for easy answers but I'm not, I just needed guidance on finishing up this project.
Carey Brown wrote:
We often get students in the Beginner forum so this is sort of expected. Also, as it is the Beginner forum, we try not to just give you the answer but to give you hints and guidance so that you can work out some of this for yourself. I hope that now that it is working that you'll study your code to fully understand how it flows.Sean Stevens wrote:Thank you so much, works fine. I know I just seem like some student looking for easy answers but I'm not, I just needed guidance on finishing up this project.
You still have unused variables and now with the addition of the loop you'll have to readjust your indentation.
When you're all done post your final result so that others may learn from it.
Cheers.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Reformat the code. In netbeans, as in other IDEs, this is a simple key combination (that I have forgotten).
All things are lawful, but not all things are profitable.
Hey! Wanna see my flashlight? It looks like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|