Fri Oct 24, 2008 5:35 pm
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Commission
{
public static void main(String[] args)
{
// declare class variables
double dollars, answer;
int empCode;
//call method
dollars = getSales();
}
//the getSales()method asks the user to input a dollar
amount and validates it
public static double getSales()
{
// declare method variables
double sales = 0.0;
boolean done = false;
//loop while not done
while(!done);
String answer = JOptionPane.showInputDialog
(null, "Enter the sales amount\n(do not use commas or dollar signs)\n
or click cancel to exit:");
if (answer == null) finish();
try
{
sales = Double.parseDouble
(answer);
if (sales <= 0) throw new
NumberFormatException();
else done = true;
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog
(null, "Your entry was not in the proper format.", "Error",
JOptionPane.INFORMATION_MESSAGE);
}
}
return sales;
}
// the finish() method ends the program.
public static void finish()
{
System.exit(0);
}
}
Mon Jul 20, 2009 8:55 am
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.