Originally Posted by
Ciaran54
So your code:
is doing very little, I think you are overcomplicating the problem a bit.
Using your method, the returned value would be quite inaccurate(I think, not actually sure what you're trying to do), as you are going up in increments of one for a double value. However, assuming this is what you want, you must first not reset i at the start of the loop, and secondly, as aussie said above, you should probably tell us what's happening in that for loop
Try this:
public double fillUp() {
double difference = capacity-amount;
for(i=amount; i<capacity; i++) {
amount++;
}
return difference;
}
that would carry the effect of filling up the tank, but it is likely to overfill. A much simpler, and more accurate way of filling up the tank would be:
public double fillUp() {
double difference = capacity-amount;
amount = capacity
return difference;
}
Thank you guys so much. It's a little embarrassing - this is my first time to ever try to sit down and write any Java code, so I am definitely almost completely ignorant. I'm still trying to wrap my mind around how to implement loops to accomplish a task.
I don't know why I tried to implement a loop here, this is so much more obvious.
The second version of the fillUp() method worked, it just needed a semicolon at the end of the third line.
Again, thanks so much!