所以我正在编写一个应该拿一个人工资(7.25美元)的程序并加上他们的佣金,然后吐出总额。我输入了所有请求的信息,我得到0.0的结果,这显然是错误的。感谢任何帮助,谢谢! 这是我在驾驶员课程中的内容:
public static void main(String [] args){
Scanner input = new Scanner(System.in);
double hours, sales, total;
DecimalFormat df = new DecimalFormat("$0.00");
Wages emp1 = new Wages();
System.out.println("Please enter the hours worked: ");
hours = input.nextDouble();
System.out.println("Please the amount of sales: ");
sales = input.nextDouble();
System.out.println("Your total pay check wages are: " + df.format(emp1.getEverything()));
}
这里是我创建的工资类别:
public class Wages {
private double PAY_RATE = 7.25;
public double sales, commission, total;
public int hours;
public Wages(){
}
public Wages(double rate,double sales, double total, double commission, int hours){
this.sales = sales;
this.total = total;
this.PAY_RATE = rate;
this.commission = commission;
this.hours = hours;
}
public double getSales(){
return sales;
}
public double getCommission(){
if(sales >= 1.00 && sales <= 99.99){
commission = (sales * 0.05);
return commission;
}
else if(sales >= 100.00 && sales <= 299.99){
commission = (sales * 0.10);
return commission;
}
else if(sales >= 300.00){
commission = (sales * 0.15);
return commission;
}
return commission;
}
public double getEverything(){
total = (PAY_RATE * hours) + commission;
return total;
}
}
答案 0 :(得分:0)
您已经创建了一个占用销售额和营业时间的构造函数,但您没有使用该构造函数,而是调用了默认值。
所以销售和工作时间没有价值。
答案 1 :(得分:0)
如果我这样做,我会改变你的工资类别,包括:
public double hours; //You're taking a double for their input, so replace the int
public Wages(double hours, double sales){
this.sales = sales;
this.hours = hours;
}
//...
public double getEverything(){
total = (PAY_RATE * hours) + getCommission();
return total;
}
并在驱动程序中使用它:
System.out.println("Please enter the hours worked: ");
hours = input.nextDouble();
System.out.println("Please the amount of sales: ");
sales = input.nextDouble();
Wages emp1 = new Wages(hours, sales);