Friday, 6 September 2013

Have JOptionPane/parse ignore a currency symbol if the user was to input it

Have JOptionPane/parse ignore a currency symbol if the user was to input it

I'm currently a student in an entry level Java class and our professor is
having us make a financial calculator of sorts. Anyhow, I want to go one
step ahead of what I already know and make it so that if a user was to
enter a $ sign before the value I ask of them in an input dialog, that it
WOULD NOT throw the entire program off. Currently, if I input a value of
10 or even 10.00 my program doesn't mind. But a typical user might input
$10.00.
I believe the reason it throws the program off is because I parse the
double after I input a string to represent it. And I don't believe that I
can parse a currency symbol. You may notice in my source that I inputted a
currency package, but I really don't know how to implement that.
My code.... so far:
import javax.swing.JOptionPane;
import java.text.NumberFormat;
class Program1 {
public static void main(String[] args) {
String WageInput = JOptionPane.showInputDialog("Enter the numeral
representing your hourly wage");
double HourlyWage = Double.parseDouble(WageInput);
String HoursInput = JOptionPane.showInputDialog("How many hours do you
work a week");
double HoursAWeek = Double.parseDouble(WageInput);
}
}
The project description by my Professor, for the note:
Using the JOptionPane class, your java application should ask a user for
hourly pay rate, hours worked per week, then calculate the annual salary.
Then it should ask the user to input a desired percentage raise, and
calculate the annual salary assuming the raise is received, and list the
difference between starting annual salary and annual salary with the
percentage raise.

No comments:

Post a Comment