LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 887 users online 158932 members 1455 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Video | Dictionary | News | FAQ
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
5 online / 50 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Help with troubleshooting Java
Replies: 7Last Post Sep. 25, 2007 11:35pm by brookie chookie23
Single page for this topic Email Print Favorite
( brookie chookie23 )


^ This is how I do it.

Patron
Tech Support Leader
Reply
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.

-------
Check out my:
Art|Blog|Website|MySpace


10:40 pm on Sep. 25, 2007 | Joined Nov. 2004 | 876 Days Active
Join to learn more about brookie chookie23 Australia | Straight Female | 4431 Posts | 26113 Points
vector3df

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


-------
Duke By the Grace of His Majesty the King of the United Kingdom of Deep
Thoughts and Random Musings, Defender of the Faith


10:45 pm on Sep. 25, 2007 | Joined Sep. 2007 | 39 Days Active
Join to learn more about vector3df Ontario, Canada | Straight Male | 2242 Posts | 2568 Points
( brookie chookie23 )


^ This is how I do it.

Patron
Tech Support Leader
Reply
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.

-------
Check out my:
Art|Blog|Website|MySpace


10:57 pm on Sep. 25, 2007 | Joined Nov. 2004 | 876 Days Active
Join to learn more about brookie chookie23 Australia | Straight Female | 4431 Posts | 26113 Points
vector3df

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

-------
Duke By the Grace of His Majesty the King of the United Kingdom of Deep
Thoughts and Random Musings, Defender of the Faith

11:10 pm on Sep. 25, 2007 | Joined Sep. 2007 | 39 Days Active
Join to learn more about vector3df Ontario, Canada | Straight Male | 2242 Posts | 2568 Points
( brookie chookie23 )


^ This is how I do it.

Patron
Tech Support Leader
Reply
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.

Post edited at 11:15 pm on Sep. 25, 2007 by brookie chookie23

-------
Check out my:
Art|Blog|Website|MySpace


11:14 pm on Sep. 25, 2007 | Joined Nov. 2004 | 876 Days Active
Join to learn more about brookie chookie23 Australia | Straight Female | 4431 Posts | 26113 Points
vector3df

Professional
Reply
System.out.println should still work.

Try System.err.println...

Do you understand the concepts of stdout and stderr?

-------
Duke By the Grace of His Majesty the King of the United Kingdom of Deep
Thoughts and Random Musings, Defender of the Faith


11:15 pm on Sep. 25, 2007 | Joined Sep. 2007 | 39 Days Active
Join to learn more about vector3df Ontario, Canada | Straight Male | 2242 Posts | 2568 Points
( brookie chookie23 )


^ This is how I do it.

Patron
Tech Support Leader
Reply
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

-------
Check out my:
Art|Blog|Website|MySpace


11:20 pm on Sep. 25, 2007 | Joined Nov. 2004 | 876 Days Active
Join to learn more about brookie chookie23 Australia | Straight Female | 4431 Posts | 26113 Points
( brookie chookie23 )


^ This is how I do it.

Patron
Tech Support Leader
Reply
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.

-------
Check out my:
Art|Blog|Website|MySpace


11:35 pm on Sep. 25, 2007 | Joined Nov. 2004 | 876 Days Active
Join to learn more about brookie chookie23 Australia | Straight Female | 4431 Posts | 26113 Points
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic