File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

non-static method construction

 
Wolfgang Obi
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • 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.

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic