• Post Reply Bookmark Topic Watch Topic
  • New Topic

having trouble passing value from sub class to super class  RSS feed

 
Kip Bodey
Ranch Hand
Posts: 43
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so the first thing we did was make a program called memory calculator. now we are supposed to make a sub class that modifies the program to also do exponents and natural logs. Then to make a new class that acts as the driver for what is now called the scientific memory calculator which includes the exponent and log. I have watched this through debug and im a little confused. first off it creates a variable for currentValue in current and in sci which are my instances, which i dont think is what i really want to do, I am unsure how to get the things in the Scientificmemcalc to do stuff without calling them directly. so when i try to do the power feature it does everything correct but it sets the sci current value to the correct answer, and now i cant figure out how to pass it on to the current current value.

this is the memory calculator


this is the scientificmemcalc


this is the scientificdriver

 
Andy Ball
Greenhorn
Posts: 20
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kip,

I'm not fully clear on what you're trying to achieve. Should ScientificCalcDriver be extending ScientificMemCalc?

If it does, then this may be the solution for you ( I'm not sure?)
Basically I've commented out the call to the MemoryCalculator object current and refactored all references to 'current' to now be 'sci' which is your ScientificCalcDriver object.

It seems to work, - at least the power function does.

<< Moderator edit -- removed code. We appreciate an eagerness to help out a fellow rancher but we encourage everyone here to DoYourOwnHomework(←click). Spoonfeeding of code is strongly discouraged. >>

Hope that assists,

- Andy

 
Kip Bodey
Ranch Hand
Posts: 43
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no ScientificMemCalc should be extending MemoryCalculator... and then my professor told me to make a driver class called ScientificCalcDriver to show what the new class does. I figured out my last problem like every thing now works the way it should. I am however not sure i guess if i have set everything up right. I made changes in ScientificCalcDriver i just set the current instance equal to my sci instance. I guess now im more curious about i guess my approach. for instance is scientificmemcalc a sub class of memcalculator?







This is what i changed to make it work right
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!