File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Pass by Value Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pass by Value Problem " Watch "Pass by Value Problem " New topic

Pass by Value Problem

Rich Charlton

Joined: Nov 11, 2004
Posts: 19
Hi all,

Im trying to do a simple value passing operation i cant seem to get it working correctly. I have two classes one which produces a value and the other that needs that value to do something with it. I have written the code, although i do not get the right result, when i click the confirm button and enter how many tickets i would like the showID integer to be passed over to Cost class using method at the bottom of panel class. I think i have a problem with my call method as it is duplicating the fram twice after i enter a number into the input dialog. Heres my code:

Panel class:

Cost class:

I have highlighted areas of code that are the problem areas.

Does anyone have any ideas why im not getting the desired result ?


[ edited to break long lines of code -ds ]
[ November 27, 2004: Message edited by: Dirk Schreckmann ]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
A combination of more detail and less detail would be more helpful to all of us, I think. You didn't really specify very clearly where exactly the error was occurring and what results you were seeing and expecting. It seems like we'd have to read through all the code to try to first figure out where the problem is occurring...please try to be more specific...
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
To start I changed the class name from Panel to MyPanel (saver confusion with sun's Panel class)

Here's a few modifications, but there's still something wrong
your 2nd panel is due to these 2 lines in Cost()
Panel cust;
cust = new Panel();

I changed those to a parent (if that is what you are trying to do)

the problem is here (in changing num1 = cust.getnum() to num1 = parent.getnum())
in MyPanel() num = 1, 2 or 3
so num1 = 1, 2 or 3
then your if/else tests for num1 > screen1, screen2 and screen3 (values are 50, 75, 100)
so "Booking Not Accepted" is always the result. The if/else is also the wrong way around
if > 50
else if > 75
else if > 100

if num1 is 100, the if > 50 will execute, which is probably not what you want
perhaps these should be < 50 etc (or start at 100, and work back)

this line was also a problem
if (day != "1" || month != "Apr" || year != "2004")

changed to !day.equals("1") etc

hope this makes sense

[ edited to remove the evil tab character and break long lines in the code -ds ]
[ November 27, 2004: Message edited by: Dirk Schreckmann ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
As Stephen says, you still haven't provided the right information for us to help you. What happens when you compile and run this program? What is the output and how does this differ from what you expect? Where exactly in your code do things seem to be going wrong? If you can be more specific about your problems, we will be able to give you some more helpful information and hints about how to fix the problem.


Java API Documentation
The Java Tutorial
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
Welcome to JavaRanch, Rich C!

Please change your display name to comply with The JavaRanch Naming Policy. Unfortunately an initial ('C') does not conform to the rule.

Thanks Pardner! Hope to see you 'round the Ranch!

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Rich Charlton

Joined: Nov 11, 2004
Posts: 19
Hi all,

I have sorted my parameter passing problem now. everything is working

Big thanks to Michael for explaining my problems.

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Congratulations! And thank you for changing your display name!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Pass by Value Problem
jQuery in Action, 3rd edition