Jump to content

why doesn't my calculator work? - JAVA

hirushaadi
Go to solution Solved by shadow_ray,
4 hours ago, hirusha.adikari said:

and why cant i keep this a double with the getText

Double.parseDouble(str)

 

2094602463_2020-12-1111_44_37-Calculator-Basic-dark-NetBeansIDE8.2.png.f3df9ec681caf1bb37b1d1e666e7480c.png

 

21059241_2020-12-1111_44_08-Calculator-Basic-dark-NetBeansIDE8.2.png.9add7029db0df7c3e681188428a871c0.png

 

2133198967_2020-12-1111_45_46-Calculator-Basic-dark-NetBeansIDE8.2.png.97ae869bdf51fa5529553d5aa17377fe.png

 

496264794_2020-12-1111_45_58-Calculator-Basic-dark-NetBeansIDE8.2.png.a534e4d6792f22f26fe7556391bbffe5.png

 

what ever i type, the answer i get is 32.0

 

and why cant i keep this a double with the getText

213200610_2020-12-1111_50_20-Calculator-Basic-dark-NetBeansIDE8.2.png.69285989f26530dc305258c345b52996.png

 

I USE NETBEANS

 

ANY HELP WOULD BE APPRECIATED - Thank You!

hey! i know to use a computer

Link to comment
Share on other sites

Link to post
Share on other sites

getText() returns a string, you have to convert it to a double before you can do any math on it.

Link to comment
Share on other sites

Link to post
Share on other sites

also get in the habit of using ( ) where convenient. 

 

For example  :

 

result = 9/5*hirusha+32   

 

Will give the right value in the result variable, because  division and multiplication have the same priority if my Java knowledge is accurate, so they'll be processed left to right , 9 / 5 and then the result multiplied by hirusha variable ... but for clarity it would be best to write  (9/5) * hirusha + 5  - this way any reader instantly knows the result of the fraction is multiplied, and you definitely didn't mean   9 / ( 5 * hirusha) 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, hirusha.adikari said:

and why cant i keep this a double with the getText

Double.parseDouble(str)

 

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×