我知道这更像是一个以数学为导向的问题,所以我对此犹豫不决,但我觉得你们都可以提供一些帮助。试图计算我的代码的双倍时间区域。
import java.text.NumberFormat;
import java.util.Scanner;
public class Wages {
/**
* @param args
*/
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
final double Rate = 9.32; // minimum wage
final int Standard = 40; // working hours until time and a half 41-60
final int Double = 60; // 61+ hours is overtime
double pay = 0.0;
System.out.print ("How many hours have you worked?: ");
double Hours = kb.nextDouble();
System.out.println();
//Give out different pay grades depending on hours
if (Hours > Double)
/* Problem on this line: */
pay = (Standard * Rate) + ((Standard+20) * (Rate * 1.5)) + ((Hours-Double) * (Standard * 2)); //Double pay**
else if (Hours > Standard)
pay = Standard * Rate + (Hours-Standard) * (Rate * 1.5); // Time and a half
else {
pay = Hours * Rate; // Standard
}
//Output earnings
NumberFormat fmt = NumberFormat.getCurrencyInstance();
System.out.println ("Earnings: " + fmt.format(pay));
}
}
答案 0 :(得分:1)
让我们看一下问题界线:
pay = (Standard * Rate)
这需要40小时* 9.32美元。到目前为止一切都很好。
+ ((Standard+20) * (Rate * 1.5))
在这里,你可以在1.5倍的时候再增加60小时的工资。
+ ((Hours-Double) * (Standard * 2));
最后,您每小时支付80美元/小时,因为您使用了Standard
代替Rate
。
你的意思是:
pay = (Standard * Rate) + ((Double-Standard) * (Rate * 1.5)) + ((Hours-Double) * (Rate * 2));
答案 1 :(得分:0)
应该是(标准 - 20),不是吗?此外,它应该是(Rate * 2)。
pay = (Standard * Rate) + ((Standard - 20) * (Rate * 1.5)) + ((Hours - Double) * (Rate * 2));