• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pass by Value Problem

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

Thanks



[ edited to break long lines of code -ds ]
[ November 27, 2004: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Layne
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Rich Charlton
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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

Big thanks to Michael for explaining my problems.

 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congratulations! And thank you for changing your display name!
reply
    Bookmark Topic Watch Topic
  • New Topic