The scenario: I have to design a program which acts as a pay machine for a parking lot. Two of the objective that program has to achieve are to calculate how long the visitor stayed in the car park, and to calculate how much the visitor owes. I have done some code which achieves both of these objectives in a separate java file for testing purposes, and it worked. The problem is, when I put it into the script with all my GUI stuff, it didn't calculate the amount owing correctly.
I have discovered that this problem has something to do with where the values for month, day, hour, minute, second, etc are intialised. I have used two if functions which set values for the date and time that the car was parked depending on what parking ID the user inputs. These variables were initalised globally, i.e:
My if functions look like this:
From what I can see, neither of the if functions are being executed, because the calculated cost is something ridiculous (5.8... x e^70), and when I tried removing the if functions from my test java file, it produced that same number.
I don't know how many (if any) java geeks we have on LiveWire, but if you are one I'd greatly appreciate your help. I can send you both the test script and the program script if it helps you understand more about the problem.
I had placed 'int' at the start of the line that retrieves the inputted value from the text box and sets it as a variable. The variable had already been initialised globally, so it was chucking a fit when I told it to initialise again.
System.out.println should still work. Try System.err.println...
Try System.err.println...
I tried it with no luck. I just tried putting it in the title of one of the windows and the inputID came up as 0... which means there's a problem retrieving the inputID from the text box where the user inputs it. That's odd though, because it was working fine before, and I haven't touched any of that part of the coding
Do you understand the concepts of stdout and stderr?
No :S
I'm rather rusty on Java, but try removing the conditionals and seeing what happens when your code gets executed. i.e Code: ... inputID = ID1; year=data[6]; month=data[5]; day=data[4]; hour=data[3]; minute=data[2]; second=data[1]; ...
i.e
When I do that, the amount owing is calculated correctly. That means that there's definitely something wrong with the if functions or their conditions, right? I've checked that the ID1 and ID2 variables are correct three times now. Maybe it's something small that I've overlooked.