📄 final_payroll.java
字号:
import java.util.*;
import java.io.*;
/**
* This is a Employee class which is used to record the full-time and part-time employee data,
* calculation of the employee amount, tax and holiday, and display the detail data of specific employee
*/
abstract class Employee implements Serializable
{
/** id is to store the employee's id number, 2 letters followed by 4 digits*/
String id;
/** A non-empty employee's storing*/
String name;
/**To store the payrate of the emlopyee (and must be >0). It is the monthly pay for FulltimeEmployee, hourly rate for ParttimeEmployee*/
double payRate;
/**an array of Payment objects (max 50 payments)*/
Payment[] payments =new Payment[50];
/** A constructor which accepts data for, and initializes id, name and payRate.*/
public Employee (String id, String name, double payRate)
{
this.id=id;
this.name=name;
this.payRate=payRate;
}
/** The function for returning id in string*/
public String getId()
{
return (id);
}
/** The function for returning name in string*/
public String getName()
{
return (name);
}
/** The function for returning payrate in double*/
public double getPayRate()
{
return (payRate);
}
/** The function for setting id in string*/
public void setId(String id)
{
this.id = id;
}
/** The function for setting name in string*/
public void setName(String name)
{
this.name = name;
}
/** The function for setting payRate in double*/
public void setPayRate(double payRate)
{
this.payRate = payRate;
}
/**A method toString which returns a String which presents an employee object in the following format.
*Payments:
* Date Hours Amount
* 22/8/2006 20 $4000.00
* 29/8/2006 30 $6000.00
* 3/9/2006 20 $4000.00
*Year pay up to today:
* Amount: $14000.00
* Tax: $0.00
*/
public String toString()//overridden is needed
{
int total_payment=0;
String return_string="";
boolean pass=true;
while ((total_payment<50) && (pass==true))
{
if (payments[total_payment]==null)
pass=false;
if (pass!=false)
total_payment++;
}
for (int i=0; i<total_payment; i++)
{
return_string=return_string+payments[i].toString();
}
String amount_string="$"+String.format("%.2f", calcYearPayment());
String tax_string="$"+String.format("%.2f", calcYearTax(calcYearPayment()));
return ("Payments:\n"+Payment.headerString()+return_string
+"Year pay up to today:\n"
+String.format(" Amount:%13s", amount_string)
+"\n"
+String.format(" Tax:%16s", tax_string)
+"\n");
}
/**abstract method pay that adds a payment to the employee*/
public abstract void pay();//abstract class
/**An method calcYearPayment that calculates the yearly payment (up to today) of the employee from the array payments.*/
public double calcYearPayment()
{
double total_payment=0;
int i=0;
boolean pass=true;
while ((i<50) && (pass==true))
{
if (payments[i]==null)
pass=false;
if (pass!=false)
{
total_payment+=payments[i].getAmount();
i++;
}
}
return (total_payment);
}
/**
* A method calcYearTax that calculates the yearly tax (up to today) of the employee
* from on the yearly payment (up to today). The calculation of the tax is:
* If yearly payment <= 100000, then tax = 0;
* If yearly payment > 100000, then tax = (yearly payment
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -