
A little Help!
Can anyone help me with this little problem, I need to make my sum a
float so that the numers I multiply can be decimal numbers. I would
really appreicate it . Thanks, Eric
import javax.swing.JOptionPane;
public class paycheck{
public static void main( String[] args )
{
String hours, // Hours worked
name, // Name of worker
rate; // Hourly rate
int number1, // first number to multiply
number2, // second number to multiply
sum; // sum of both numbers
// Prompt user to enter name
name = JOptionPane.showInputDialog( "Who Goes There?" );
// Prompt user to enter hours worked
hours = JOptionPane.showInputDialog( "Please enter your hours worked"
);
// Prompt user to enter horly rate
rate = JOptionPane.showInputDialog( "Please enter your hourly rate"
);
// convert from string to int
number1 = Integer.parseInt( hours );
number2 = Integer.parseInt( rate );
// multiply the numbers
sum = number1 * number2;
// display the check
JOptionPane.showMessageDialog( null, "Pay to the order of: " +
name + sum, "PayCheck", JOptionPane.PLAIN_MESSAGE );
System.exit(0);
}
}

Re: A little Help!
Are you asking how to declare a variable as float? That would be
float sum;
And I expect you don't want your hourly rate variable to be an integer,
unless you're living in a country where the currency is almost worthless.
So declare your "number2" variable (not a good choice of name) as float
also, and calculate it as Float.parseFloat(rate).
PC2
"Eric" <wdiv@hotmail.com> wrote in message news:3ac26075$1@news.devx.com...
>
> Can anyone help me with this little problem, I need to make my sum a
> float so that the numers I multiply can be decimal numbers. I would
> really appreicate it . Thanks, Eric