You claim that nothing happens after line 35. I claim that is false. Add println() calls after line 38 and at various places inside Calc2.loop(), so that you can see what's happening.
As a side note, "class1" is a really lousy variable name for a variable of type Calc2. I know, "oh, this is just a small test program, etc. etc.," but it's already confusing, and if the program gets bigger or you get into the habit, you're just going to be setting yourself up for lots of frustration.
When it hits like 38 ... which is suppose to be Class Calc2.
And the class1 is just to see if its going to work. Variable can be changed after the code is working. I have been trying just to get this done for 6 straight hours, and my nerves are a little on edge :/
Johnathan Conkle wrote:No I did nothing happens after 35.
I maintain that that is false. The JVM continues to execute code. What you are telling me is that it is not creating a new Calc2. And you are telling me that it is not invoking the loop() method in that new Calc2 object.
You are telling me it is not executing this line in the loop() method:
nor this one:
And so on.
I maintain that these claims that you make are false. But I'm not asking you to just believe me. I'm asking you to add print statements so you can observe for yourself what is happening.
This is how we debug. We make predictions on how the code will behave, and when it doesn't match our expectations, we sometimes have to observe the actual behavior at a detailed level to see where our assumptions are wrong. If you're not willing to check your assumptions, you'll be beating your head against the wall forever.
And the class1 is just to see if its going to work. Variable can be changed after the code is working.
I know this. And yet I made the suggestion anyway. Better to get into the habit of taking a few seconds to come up with meaningful identifiers in the first place.
I have been trying just to get this done for 6 straight hours, and my nerves are a little on edge :/
I understand that, believe me. And I'm not trying to jerk you around here.
I'm trying to lead you down the path toward finding out what the problem is, and also teach you some tools to help you solve these problems on your own in the future.
I see one definite problem, and one potential problem. The potential problem is that you should only ever use one Scanner in a given application. I'm not sure if that will cause you any problems here, but it could.
The actual problem has to do with your apparent assumption that it should just continue on after nextDouble() without any help from the user? (Although if the other one is indeed causing a problem, then even if the user does his part, it may look like nothing is happening.)
Johnathan Conkle wrote:Okay I was able to get the loop to go through and everything to work thank you for helping me out. But now for some reason. When the loop hits it returns 0 no matter what the user inputs.
Cool. Glad you worked it out!
As for the "always 0" problem, the same suggestion applies: Add some println() calls so you can see which code paths are being executed and what the various values are along the way.
Johnathan Conkle wrote:But the problem is its a loop I can't just throw a random print line
Yes you can.
... because theres not gonna be a value. The whole loop has no value.
Who said anything about a "value of the loop"?
Your loop is executing various steps. So you can print out whatever you want to indicate which of those steps are being executed. You can see how many times the loop body is being executed, and which if/else paths are being taken.
And it's performing computations and setting variables, so you can see what the results of those computations are along the way, what values are being assigned to the variables.
Cant you look over the code and check where it may be ...?
I could, but if it were my code and I was confused about why I wasn't seeing the expected behavior, I wouldn't waste much time on that before I started printing stuff out or using a debugger, and I'm certainly not going to expend more effort on somebody else's code than I would on my own.
However, if you add the print statements and still can't figure out what's going on, then post the latest code, and tell us what you saw vs. what you expected to see, and somebody will help you from there.
I was able to get the loop to work if the user puts in any from 120,000+ or 96000+ or higher .. but anything lower then 95999 will not work and I am looking at the line but it seems no different from the rest. I guess thats why I am getting so frustrated lol.
Assuming the problem is the loop on line 18 of the Calc2 class, put in a line that prints the value of i right after line 18, before your "if (num >= 120000.00)" line. I'd also print out what num is. I would also add a a println after you update num with what the new value is.
after some period of time, posts are locked from editing. If people go back and edit things, it can make the rest of the thread even more confusing, as people are answering questions that are gone or referring to lines of code that aren't there.
Johnathan Conkle wrote:Lol can we not edit posts?.
If there is some kind of problem with a post, contact a moderator (bartender, sheriff, etc) and they will review your request. If you have new, updated source code, just make a new post with the current code and ask your question in relation to that.
Johnathan Conkle wrote:Well if I knew what the problem was ... I would have fixed it is the problem.
That's the whole point. You don't know what the problem is. And neither do I. So you need to do some work to find out what the problem is. If it were my code, the way I would do that is, as I suggested many times, to add a bunch of print statements so we can observe what's actually happening.
We write the code. We make assumptions and expect it to behave a certain way. The code behaves differently than we expect. We see step 1, and then there's a black box of steps 2 through 10, and then where step 11 should be we see something else, or nothing at all. So obviously our assumptions about what 2-10 does was wrong. At least one of those steps is doing something different than we expected. How do we figure out which steps?
We could just stare at the code and hope we figure it out. That's a valid approach, up to a point. But at some point the same assumptions that led us to write the wrong code in the first place are going to continue to lead us to mis-predict its behavior when reading it. So if a little starting and mental or pen-and-paper walk-through doesn't work, we need to watch what the code is doing. One simple way to do that is to print out which steps are executing and what their results are.
So my question to you is: Why are you so resistant to following my suggestion? What will you do when you get stuck on your next program? You could just throw your hands up and ask somebody else to find it, like you're doing here, or you could use the technique I'm trying to teach you, so that you can find the problem yourself.