This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Passing values between classes in two separate files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing values between classes in two separate files" Watch "Passing values between classes in two separate files" New topic
Author

Passing values between classes in two separate files

Vern Vernetta
Greenhorn

Joined: May 01, 2010
Posts: 2
So I'm using two separate files for the first time and seem to be having trouble passing the values. The program should add, subtract, multiply, and divide fractions printing the inputted fractions and the result.

The two files are as follows:


and file two:


When I try to run the program, it prints 0 / 0 fractions leading to a NaN result. My guess is that the values read in the first file are not being passed to the second file, but I'm unsure how to correct it.

I'd really appreciate any insight into why this is happening.
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Look at your constructor in P4Rational. You assigned the values of your membrer variables to your local variables. It's not what you wanted to do.
Change your constructor



in the following one:



You did that in the one parameter constructor too:



You must change it in:




Bye,
Nicola
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38467
    
  23
And welcome to the Ranch
 
 
subject: Passing values between classes in two separate files