Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Java Programming 24-Hour Trainer by Yakov Fain
This is the forum to discuss the Wrox book Java Programming 24-Hour Trainer by Yakov Fain; ISBN: 978-0-470-88964-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Java Programming 24-Hour Trainer by Yakov Fain section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 26th, 2012, 03:58 AM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Cool Lesson 9

Hello,
can someone help me with this code (it is a calculator with ActionListener):

Code:
else if (src == referenca.buttonPlus)//when someone press button +
			{
				
num=referenca.getDisplay();//gets the number that someone typed and saves it into variable num

numStringToDouble = Double.parseDouble(num);//Converts String to Double 

matOperacija="+"; //saves mathematical operations - I have set this variable to be INT but I am not sure what should it be INT,CHAR,STRING...
							
referenca.setDisplay ("",""); //sets blank display 
				
			}
			
//the same as buttonPlus
			else if (src == referenca.buttonMinus)
			{
				num = referenca.getDisplay();
				numStringToDouble = Double.parseDouble(num);
				matOperacija="-";
				
				referenca.setDisplay("","");
			}
			
			else if (src == referenca.buttonEqual)
			{
String equal= referenca.getDisplay();//gets displayed number

Double newEqual =Double.parseDouble(equal);//converts displayed number into double

Double result = //here is where I should use a mathematical operation but I do not know how.

String newResult = Double.toString(result); // converts Double into String
				
referenca.setDisplay(newResult);//sets display to a new result
				
			}
My problem is that I do not know how to do this: When I type first number and a mathematical operation that number is saved into variable numStringToDouble and so is mathematical operation saved into matOperacija (not sure what type should I use int or String or Char) and then when I type number two and press equal number on the display should be added, multiplyed etc. whit the number saved in a variable numStringToDouble. My biggest problem is that I do not know how to deal with mathematical operations. How to save them and how to use them.
Reply With Quote
  #2 (permalink)  
Old November 27th, 2012, 01:11 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Solution

Im stucked exactly here, dont know how to do it, can you help me find the solution?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 8 - Try It Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 4 February 12th, 2012 08:44 AM
Lesson 7 Joakim BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 1 November 30th, 2011 11:16 AM
Lesson 4 - Try It brookesmith BOOK: JavaScript 24-Hour Trainer 2 September 15th, 2011 05:40 PM
Lesson 4 Mtheys BOOK: Java Programming 24-Hour Trainer by Yakov Fain 3 September 15th, 2011 05:02 AM
Lesson 6 Try It zavodney BOOK: Stephens' Visual Basic Programming 24-Hour Trainer 2 June 6th, 2011 10:07 PM



All times are GMT -4. The time now is 09:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.