aspose file tools*
The moose likes Beginning Java and the fly likes non-static method construction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "non-static method construction" Watch "non-static method construction" New topic
Author

non-static method construction

Wolfgang Obi
Ranch Hand

Joined: Dec 05, 2005
Posts: 134
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

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Wolfgang Obi
Ranch Hand

Joined: Dec 05, 2005
Posts: 134
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

Joined: Jan 29, 2003
Posts: 8791
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: non-static method construction