這裏是我的任務細節:計算週薪 - 總價值不正確
編寫一個Java程序,可以用來計算小時薪僱員的週薪。 計劃最初接受員工的ID,工作小時數和小時工資率。 員工可能需要額外工作時間。發生這種情況時,額外的小時數必須加上原始金額 ,並重新計算工資。該程序必須在單獨的 行輸出員工的身份證號碼,工作小時數,小時工資率和工資,對於每個員工 。此外,該方案還必須輸出的錢由 公司
這裏支付的總金額是我到目前爲止
包工資;
public class Payroll
{
private static double TotalPayout;
private double Hours;
private double Hourly_Rate;
private String EmployeeId;
public static double Salary;
private double increaseHours = 10;
public Payroll (String getEmployeeId, double getHours, double
getHourly_Rate)
{
EmployeeId = getEmployeeId;
Hours = getHours;
Hourly_Rate = getHourly_Rate;
Salary = Hours * Hourly_Rate;
TotalPayout = TotalPayout + Salary;
}
public static double getTotalPayout()
{
return TotalPayout;
}
public String getEmployeeId()
{
return EmployeeId;
}
public double getHours()
{
return Hours;
}
public void increaseHours (double x)
{
Hours = increaseHours + Hours;
}
public double getHourly_Rate()
{
return Hourly_Rate;
}
public double calculateSalary()
{
Salary = Hours * Hourly_Rate;
return Salary;
}
}
package payroll;
import java.util.Date;//Used for creating a Date object
import java.text.DateFormat;//Used for specifying the format of the date
import java.text.NumberFormat;//Used for specifying the type of currency
public class TestPayroll
{
public static void main (String [] arg)
{
//Set up the formatters
Date d = new Date();
DateFormat df = DateFormat.getDateInstance();
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println("ABC Company");
System.out.println ("\nPayroll For Week Ending " + df.format (d));
System.out.println("--------------------------------------");
//Define employee 1
Payroll employee1 = new Payroll ("444-4444", 30, 25);
employee1.calculateSalary();
displaySalary (employee1, nf);
//Define employee 2
Payroll employee2 = new Payroll ("555-55555", 20, 50);
employee2.calculateSalary();
displaySalary(employee2, nf);
System.out.println("\tIncrease " + employee1.getEmployeeId() + " by 10
hours");
employee1.increaseHours(10); // 10 hours increase
System.out.println("\tEmployee # ...... " + employee1.getEmployeeId());
System.out.println("\tHours Worked:.... " + employee1.getHours() + "
hours");
System.out.println("\tHourly Rate:..... " + nf.format(employee1.getHourly_Rate()) + "/hour");
System.out.println("\tYour Salary is .. " + nf.format(employee1.Salary));
System.out.println("\t------------------------------");
System.out.println("Total Payout Amount..... " + nf.format(Payroll.getTotalPayout()));
System.out.println("-------------End of Report------------");
}
public static void displaySalary (Payroll e, NumberFormat nf)
{
System.out.println("\tEmployee # ...... " + e.getEmployeeId());
System.out.println("\tHours Worked .... " + e.getHours() + " hours");
System.out.println("\tHourly Rate ..... " + nf.format(e.getHourly_Rate()) + "/hour");
System.out.println("\tYour Salary is .. " + nf.format(e.calculateSalary()));
System.out.println("\t------------------------------\n");
}
}
不只是代碼轉儲,最大限度地減少你的問題,並告訴我們你做了什麼,以及你在掙扎什麼。 –
使用浮點確切的貨幣價值是頑皮的。以整數類型工作。 – Bathsheba
屬性應該是小寫btw –