LiveWire Peer Support Network

Printable Version of Topic "Help with troubleshooting Java"

- LiveWire Teen Forums & College Forums (http://www.golivewire.com)
-- (http://www.golivewire.com/forums/support-technical.html)
--- Programming & Application Development (http://www.golivewire.com/forums/forum-211-s-0.html)
---- Help with troubleshooting Java (http://www.golivewire.com/forums/peer-ttyepb-support-a.html)


-- Posted by Brookie Chookie23 at 10:40 pm on Sep. 25, 2007

Hi. I'm doing a Java assignment for my IT class. It's a pretty simple assignment, but what's coding without errors, huh?

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:

Code:
public static int year=0;
     public static int month=0;
     public static int day=0;
     public static int hour=0;
     public static int minute=0;
     public static int second=0;

My if functions look like this:

Code:
if(inputID==ID1){
           year=data[6];
           month=data[5];
           day=data[4];
           hour=data[3];
           minute=data[2];
           second=data[1];
        }
     
        if(inputID==ID2){
           year=data[13];
           month=data[12];
           day=data[11];
           hour=data[10];
           minute=data[9];
           second=data[8];
           //sets date & time variables from array to according to ID entered
        }

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.


-- Posted by vector3df at 10:45 pm on Sep. 25, 2007

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];
...


-- Posted by Brookie Chookie23 at 10:57 pm on Sep. 25, 2007

Quote: from vector3df at 3:15 pm on Sep. 26, 2007


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];  
...


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.


-- Posted by vector3df at 11:10 pm on Sep. 25, 2007

Now trying printing the inputID and ID1 to the screen. Put it just before your if statements.


-- Posted by Brookie Chookie23 at 11:14 pm on Sep. 25, 2007

I can't print the variables because of the way the GUI was made. It uses containers and multiple windows. See, that's my problem. That's why I had to make a new script to test it.


-- Posted by vector3df at 11:15 pm on Sep. 25, 2007

System.out.println should still work.

Try System.err.println...

Do you understand the concepts of stdout and stderr?


-- Posted by Brookie Chookie23 at 11:20 pm on Sep. 25, 2007

Quote: from vector3df at 3:45 pm on Sep. 26, 2007


System.out.println should still work.

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


-- Posted by Brookie Chookie23 at 11:35 pm on Sep. 25, 2007

Never mind... I found 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.


www.golivewire.com