One line causing code to fail.
The last line before the exit is causing a problem, as far as I can see, everything is right (calculations, variables, etc...) when you take out the division line, the problem gives you your two numbers, but won't divide them in that line of code, why is that?
Code:
import javax.swing.JOptionPane;
public class Problem2
{
public static void main(String [] args)
{
double integer_one, integer_two;
String number_one, number_two, Product;
number_one = JOptionPane.showInputDialog(null,"Please enter your weekly salary:");
integer_one = Integer.parseInt(number_one);
number_two = JOptionPane.showInputDialog(null,"Please enter your hours worke:");
integer_two = Integer.parseInt(number_two);
JOptionPane.showMessageDialog(null, number_one, "Weekly Salary",JOptionPane.OK_CANCEL_OPTION);
JOptionPane.showMessageDialog(null, number_two, "Hours worked",JOptionPane.OK_CANCEL_OPTION);
JOptionPane.showMessageDialog(null,"Hourly Pay" + integer_one / integer_two ,JOptionPane.OK_CANCEL_OPTION);
System.exit(0);
}
}
Re: One line causing code to fail.
Change the last line to:
Code:
JOptionPane.showMessageDialog(null
, "Hourly Pay" + (integer_one / integer_two)
, "Payment", JOptionPane.OK_CANCEL_OPTION) ;