• 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

Passing values between classes in two separate files

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



 
Marshal
Posts: 79263
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
reply
    Bookmark Topic Watch Topic
  • New Topic