Yes that is what debugging is about. Finding out why the program produces incorrect values.it doesnt read the correct values
Then when the incorrect values are found, the program needs to be changed to produce correct values.
Good luck.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Yes that is what debugging is about. Finding out why the program produces incorrect values.it doesnt read the correct values
Then when the incorrect values are found, the program needs to be changed to produce correct values.
Good luck.
If you don't understand my answer, don't ignore it, ask a question.
You have to be not reading at all like what is going on 0 help
I'm trying to show you how to debug your code and find the problems in it. By printing out the values and finding an unexpected value (I assume 0 is unexpected) you need to look at the code to see why its initial value was 0. I assume you expected an initial value of 64. Why didn't you ask where the 0 came from?
The next observation you should make when looking at the printed out values was where did the value of 52 come from? The initial value of 0 minus 12 is -12 not 52.
So where did 52 come from? I was waiting to point that out, but you never got past saying the output for the second trial was wrong. You need to look at all the values and think about if they are reasonable.
Your expectations must have been that I would fix the code. I do not fix a student's code. I try to give debugging techniques. All programmers must know how to debug their code.
If you don't understand my answer, don't ignore it, ask a question.
I wasn't expecting you to do my code haha... i was expecting a answer that would help... if you would like i actually revised my code a lot now i just have an issue of a repeating number but ill solve this issue myself considering you don't want to help.
That is a hard statement. How many responses did I give on this thread? How quickly did I respond?you don't want to help.
What kind of responses were you looking for?
If you don't understand my answer, don't ignore it, ask a question.
Something to help me. I added a while statement but its stuck in a loop and keeps adding the amount of water i put in
public void addWater(int waterAdd){ int tempWater; do{ tempWater = MAX_JUGOUNCES - waterAdd; System.out.println("waterLeft="+ tempWater + " ounces, waterAddded="+waterAdd + " ounces."); }while(waterAdd <= 12); if(waterJug > 64){ System.out.println("Jug can't exceed 64 ounces!"); }}
What condition will stop the looping?its stuck in a loop
Does any of the code inside of the loop change the value of any variables used in that condition?
If you don't understand my answer, don't ignore it, ask a question.
System.exit();?
I dont know of any terms to stop the program from continuing of the condition is not met
I tried using 'tempWater' but I am completely stuck right now
Here is the condition that controls the looping:
(waterAdd <= 12)
as long as waterAdd is <= 12 the loop will continue.
Change waterAdd to a value > 12 and the loop will exit.
What is the purpose of the loop? All it does is compute a value for tempWater and print a message. It does not change anything.
If you don't understand my answer, don't ignore it, ask a question.
So I know what to do but i dont know how.. Once the first equation is done and it prints the message, I want whatever that jug value printed is example("User enters 12... waterJug = 52 waterAdd = 12 Now remeber that 52 value and reapply it to the same equation so that it loops until we hit 0.
Please explain in simple steps in a list describing what you want to do.I know what to do
For example the steps to get 2 numbers from a user and sum them
zero out sum field
ask for first number
read number
add number to sum
ask for next number
read next number
add number to sum
If you don't understand my answer, don't ignore it, ask a question.
Okay no problem.
1.When method is called user inputs number(stored in 'waterAdd')
2.This is than followed by a check to see if the value is any larger than 12(otherwise it cant continue)
3.If value is <= 12, the difference of 'waterAdd' and 'jugOunces'(jugOunces = 64; )
4. I now have that value stored in 'tempWater' and that is being printed to the users screen.
5.I now need, 'tempWater' to be called again to instantiate another method call like above but with the new 'tempWater' value instead of 'jugOunces'
What is 3. supposed to do when value <= 12. I do not see any actions to take.
In 5. what does 'tempWater' to be called again mean? If tempWater is a variable it can not be called. Its value can be changed.
If you don't understand my answer, don't ignore it, ask a question.
When the method is called the user enters a number
that number is taken away from jugOunces which equals 64
is there anything else i can store values in besides variables
So is the number always subtracted from 64?number is taken away from jugOunces which equals 64
That sounds like what you were complaining about earlier:
user enters 12 results is 52
user enters 10 results is 54
The result is ALWAYS 64 minus what the user entered.
Don't you want to save that results and subtract the new user input from that saved value, not from 64?
Some thing like this:
user enters 12 results is 52
user enters 10 results is 42 (52 minus 10 NOT 64 minus 10)
If you don't understand my answer, don't ignore it, ask a question.
Yes exactly what you said is what ive said 3 times. "I dont know how to do it i just know what i wanna do"
Here is an example of how to subtract or add and remember the new value:x = 10 // set initial value to 10 x = x - 3 // x is now 7 (10 - 3) x = x - 2 // x is now 5 (7 - 2) x = x + 4 // x is now 9 (5 + 4)
If you don't understand my answer, don't ignore it, ask a question.
This is what i attempted to do for tempWater and you said it wont work
Wouldnt your example be exactly mine but with x?
Please post the complete code that shows what you have attempted.This is what i attempted to do for tempWater
Is tempWater the variable that is be decremented by the amounts from the user?
I did not see any statements in your code that looked like the following:
tempWater = tempWater - amount; // decrement tempWater by amount
If you don't understand my answer, don't ignore it, ask a question.
This is what ive added and changed but
It leads to thisif(waterAdd != 13){ int tempWater = 64; tempWater = tempWater - waterAdd; // decrement tempWater by amount tempWater = tempWater - waterAdd; System.out.println("waterLeft="+ tempWater + " ounces, waterAddded="+waterAdd + " ounces."); }
jug1.addWater(12); waterLeft=40 ounces, waterAddded=12 ounces.
Is that print out what you expected? You didn't add any comments about it.
Defining tempWater as a local variable (inside of the if statement) means that its value is LOST as soon as execution leaves the if statement.
If you don't understand my answer, don't ignore it, ask a question.
jcruz16 (October 31st, 2019)
Oh ok so is there anything else i can use? so that the value is remembered for next time
Define the variable at the class level, not local.so that the value is remembered for next time
public class TheClass { // here is class level int varname; // define a variable at the class level
If you don't understand my answer, don't ignore it, ask a question.
jcruz16 (October 31st, 2019)
Thank you so much that solved everything!!!!