import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Commission
{
public static void main(String args[])
{
double dollars, answer;
int empCode;
dollars = getSales();
empCode = getCode();
answer = getComm(dollars,empCode);
output(answer,dollars);
finish();
}
public static double getSales()
{
//delcare
double sales = 0.0;
boolean done = false;
while(!done)
{
String answer = JOptionPane.showInputDialog(null,"Enter the sales amount\n(don't use commas or dollar)\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;
}
public static int getCode()
{
int code = 0;
boolean done = false;
while(!done)
{
try
{
String message = "Enter the commission code :"+"\n\n1)Telephone Sales\n2) Instore Sales\n3) Outside Sales \n\n";
code = Integer.parseInt(JOptionPane.showInputDialog(null,message));
//valid code
if(code<1||code>3) throw new NumberFormatException();
else done = true;
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"Please enter 1,2,3","Error",JOptionPane.INFORMATION_MESSAGE);
}
}
return code;
}
public static double getComm(double employeeSales,int employeeCode)
{
double commission =0.0;
switch(employeeCode)
{
case 1: commission = .10*employeeSales;
break;
case 2: commission = .14*employeeSales;
break;
case 3: commission = .18*employeeSales;
break;
}
return commission;
}
public static void output(double commission,double sales)
{
DecimalFormat twoDigits = new DecimalFormat("$#,000.00");
JOptionPane.showMessageDialog(null,"Your commission on sales of" + twoDigits.format(sales)+" is "+twoDigits.format(commission),"Commission Totals",JOptionPane.INFORMATION_MESSAGE);
}
public static void finish()
{
System.exit(0);
}
}
import java.text.DecimalFormat;
public class Commission
{
public static void main(String args[])
{
double dollars, answer;
int empCode;
dollars = getSales();
empCode = getCode();
answer = getComm(dollars,empCode);
output(answer,dollars);
finish();
}
public static double getSales()
{
//delcare
double sales = 0.0;
boolean done = false;
while(!done)
{
String answer = JOptionPane.showInputDialog(null,"Enter the sales amount\n(don't use commas or dollar)\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;
}
public static int getCode()
{
int code = 0;
boolean done = false;
while(!done)
{
try
{
String message = "Enter the commission code :"+"\n\n1)Telephone Sales\n2) Instore Sales\n3) Outside Sales \n\n";
code = Integer.parseInt(JOptionPane.showInputDialog(null,message));
//valid code
if(code<1||code>3) throw new NumberFormatException();
else done = true;
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"Please enter 1,2,3","Error",JOptionPane.INFORMATION_MESSAGE);
}
}
return code;
}
public static double getComm(double employeeSales,int employeeCode)
{
double commission =0.0;
switch(employeeCode)
{
case 1: commission = .10*employeeSales;
break;
case 2: commission = .14*employeeSales;
break;
case 3: commission = .18*employeeSales;
break;
}
return commission;
}
public static void output(double commission,double sales)
{
DecimalFormat twoDigits = new DecimalFormat("$#,000.00");
JOptionPane.showMessageDialog(null,"Your commission on sales of" + twoDigits.format(sales)+" is "+twoDigits.format(commission),"Commission Totals",JOptionPane.INFORMATION_MESSAGE);
}
public static void finish()
{
System.exit(0);
}
}
Mon May 10, 2010 2:45 am by titr
» แนวคิดแบบหมวก 6 ใบ -- มาวิเคราะห์กันๆ
Fri Dec 11, 2009 12:28 am by Admin
» หาแนวร่วม ทำซัพนรก Anime จ้า *-*
Fri Oct 09, 2009 1:46 pm by สก๊อยผ่า
» ขอเรียกร้องสิทธิให้แก่ช่วงๆ กับหลินฮุ่ย!!!
Fri Oct 09, 2009 1:44 pm by สก๊อยผ่า
» มีอะไรมาให้เล่นอีกแล้ว(เกมสร้างสถานะการณ์)
Thu Sep 03, 2009 12:14 pm by Parakan
» อยากถามวิธีใช้ถุงพลาสติก
Sun Aug 09, 2009 2:34 am by Admin
» Xnac€hecklist-ใครทำชีทหายมาอ่านได้ที่นี่
Sat Aug 08, 2009 9:08 pm by Admin
» อยากไปเที่ยวทะเลอีกอ่ะ
Fri Jul 31, 2009 1:47 pm by Admin
» มีรูปให้ดู
Thu Jul 30, 2009 7:39 pm by SoHandsome