• 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

non-static method construction

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i need help here....
my programme reads in 4 ints, and creates 2 rational numbers.

then it can carry out one of four operations (multiplication, division. addition, subtraction...) with the two fractions.

I'm having problems writing my 4 methods incharge of carrying out tge operations (subtraction, addition etc)....how exactly do i do this...?

PS: i am trying to make the methods non-static.....
i am calling them up in my main....

cheers.

 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, looks like you have a skeleton set up. Let's go from there. A method like this:

Describe it in plain language: This method subtracts the argument from the object you call it on, and returns a new rational for the answer. So we're going to use "this" and the argument as inputs, and make a new Rational to store the answer.

See if it makes sense how that uses values from "this" and the argument "r" to make something new.

Here's a great way to work on assignments like this. To keep things simple, make a new class Rat2 and write only enough code to make this work.

I know this seems trivial and silly, but it's very powerful. We know that Rat2 is 100% correct (even if it's only 6 lines long) and we can build the next method with confidence. Show us what you make!
[ June 18, 2006: Message edited by: Stan James ]
 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a million Stan!

I've rearranged the whole programme, but the results dont seem to be comming out right....where am i still going wrong?

 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enough places that it's a little hard to talk about. That's why I encouraged you to make a NEW CLASS that does only one thing - a constructor. Once that's working we can make it do the next thing. It really goes much faster and easier when you always have proven working code plus one or two lines you just typed.

Seriously, make this run first with a new class 5 or 10 lines long.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic