Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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.
  #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?


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





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