File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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: 37907
    
  22
And welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing values between classes in two separate files
 
Similar Threads
Don't know where to start???
sorting fractions problem
null pointer exception
int can not be dereferenced error
Please help with a simple GUI.