• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie trying to get calculation to work using user input from textfields  RSS feed

 
Tori Hoffman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As stated in the subject I'm a newbie when it comes to Java Programming (I'm in my second week of class). I'm trying to create a Retail Calculator for a class and need to multiply two values together (Price, Discount) in order to get the sale's price when the user hits a Calculate button. I would appreciate any help in letting me know what I'm doing wrong. The price and discount are user input values from textfields in the beginning of the code.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

In line 17 you're trying to multiply two Strings - that doesn't work, you need two numbers instead. And in line 14 you're converting a string to a double, but then you're trying to assign that double to a string variable - you need to assign it to a double variable. And then you need to convert the price to a double as well.

Note that in a real application you should never use double (or even float) for anything to do with prices because it's inexact. But I guess in your second week of coding that is acceptable.
 
Vijay Kalkundri
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I think this is what probabaly you are looking to achieve.



vvk
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!