aspose file tools*
The moose likes Beginning Java and the fly likes Programming formulas 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 "Programming formulas" Watch "Programming formulas" New topic
Author

Programming formulas

Atah Tabotnjap
Greenhorn

Joined: Mar 17, 2008
Posts: 24
Hi all

I am very very new to JAVA. I have kniowledge of the various structures of the language, but no experience. I wonder if anyone could give me an idea on the best way to go about programming a formuly that gets certain parameters (of which some are formulas by themslves) as input and gives out a value. Just an idea on how to start will be of help. Thanks a lot.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Try working out a formula which takes an int number as its input and returns an int which is the square of its input. You may get overflow errors if you pass a parameter such that |i|>46340.
The easiest way to get i^2 is i * i.

Se what you can make of that, and good luck with it.

Have you got any books? Have you been through the Java Tutorials? Have you got anybody nearby who can teach you? You will find learning programming very difficult without at least some of those resources.
Atah Tabotnjap
Greenhorn

Joined: Mar 17, 2008
Posts: 24
Thanks for the reply man. I have taken tutorials and have books, i understand a couple of things, but my problem is putting it together to . I want to start somewhere and then continue learning. YOu know learning to program without a project doesn't really do much. I want to know how i can start programming this formula. Do i need for axample just a class with methods or do i declare classes for each parameter which is itself dependent on some other parameters ?? You know that kind of stuff.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
an example:



is this what you're looking for?

disclaimer: done off the top of my head, may not compile


give it a try,
fail (we all do),
post your latest attempt, and where you're having problems,


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Atah Tabotnjap
Greenhorn

Joined: Mar 17, 2008
Posts: 24
Thanks Bill. That sounds like a good start for me
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
. . . square . . . return value * 2;


And yes, you will have to create a class to hold those methods. I think both Bill's methods could beneficially be declared static, since neither of them alters the state of any possible object.

And as written, you will have to declare the methods static to get it to compile.
Atah Tabotnjap
Greenhorn

Joined: Mar 17, 2008
Posts: 24
Hi Ritschie, Bill

sorry to bug you, like i said earlier, i am very new to programming and will be asking very basic questions.

I am trying to write basic code where i can input variable values from a keyboard and get an output. Hot do i write such code that takes input ?

Thnaks
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Java I/O example
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
If you are using JDK 5 or later, you will probably find a Scanner easier to use for input:


"I'm not back." - Bill Harding, Twister
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Programming formulas