在你的外部 while 循环中,你需要这个:
overtime = 0;
if (hoursWorked>8)
overtime = (hoursWorked-8)*(rateOfPay*1.5) - (hoursWorked-8)*rateOfPay; // Calculate OVERTIME HOURS
将每次迭代的加班时间设置为零,您必须减去加班时间的正常费率(否则您添加两次)
然后你必须把加班加到工资中:
wages += (hoursWorked * rateOfPay) + overtime;
将所有内容放在一个 do-while 循环中,并在开始时设置 day=1,如下所示:
String choice = "Y";
do {
day=1;
while (day <= 5) // on weekday
...
最后:
...
} //end while loop for weekend.
choice = JOptionPane.showInputDialog(null, "Do you want to calculate another weeks wages -Yes or No?", "TRY AGIN", JOptionPane.PLAIN_MESSAGE);
} while (choice.equals("Y") || choice.equals("y"));
JOptionPane.showMessageDialog(null, "Pay this week is £" + wages, "Pay", JOptionPane.PLAIN_MESSAGE);
对于你的额外问题-'在开始:
double totalWages = 0;
String choice = "Y";
do {
day=1;
wages = 0;
...
最后:
...
JOptionPane.showMessageDialog(null, "Pay this week is £" + wages, "Pay", JOptionPane.PLAIN_MESSAGE);
choice = JOptionPane.showInputDialog(null, "Do you want to calculate another weeks wages -Yes or No?", "TRY AGIN", JOptionPane.PLAIN_MESSAGE);
totalWages += wages;
} while (choice.equals("Y") || choice.equals("y"));
JOptionPane.showMessageDialog(null, "Pay total is £" + totalWages, "Pay", JOptionPane.PLAIN_MESSAGE);