This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: I need some calculation help
 
Similar Threads
How can I add error handling facilities to this code?
Print Statement help
add totals after Gifts object keeps track of input
College Assignment
getParameter question