aspose file tools*
The moose likes Beginning Java and the fly likes I need some calculation help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I need some calculation help" Watch "I need some calculation help" New topic
Author

I need some calculation help

Stephenie Jannings
Greenhorn

Joined: Apr 12, 2002
Posts: 1
I have an assignment to make a calculator. This has to be done on a BorderLayout with a panel set to GridLayout. All that has been accomplished; however, to get the results to calculate is causing me great pain.
if(e.getSource()==b10)
total=(total*10)+8;
t.setText(""+total);
This is the code that I have for the numbers to appear. I need to somehow get the number that will be inputted to add, subtract, multiply, and divide another number that will be inputted.
Any suggestions will greatly be appreciated. Thanks
expired user
Greenhorn

Joined: Dec 13, 2001
Posts: 11
I have a code for calculator whic i designed. Try this code and check out if it helps you.

(edited by Cindy to format code)
[ April 14, 2002: Message edited by: Cindy Glass ]
Jake Westphal
Greenhorn

Joined: Apr 10, 2002
Posts: 4
A note on OO design with regard to the code above, I read a good article about using inner classes to remove large switch or if/if else statements. It helped me understand good, real world uses for anonymous classes.
It would change the code above so that each button has its own implementation of actionPerformed, and thus, the large if/if statement in actionPerformed is not needed.
Here is the article:
Inner Classes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I need some calculation help