LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 698 users online 225410 members 1259 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
burn the banks
when i split a dutch and fill it up!
Mood: Carefree
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
6 online / 30 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Quoting Post
Archived Topic: It will not be bumped to the top of the forum.
Topic Help with troubleshooting Java
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
Brookie Chookie23 Posted 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.

Replies
Brookie Chookie23 Posted 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.

Brookie Chookie23 Posted 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

vector3df Posted 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?

Brookie Chookie23 Posted 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.
vector3df Posted 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.
Brookie Chookie23 Posted 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.

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

All 7 previous replies displayed.