工资管理软件设计(Java)

package experiment2;


public class Staff {


static StaffMember [] Stafflist=new StaffMember[6];
    void paydatail() {
    for(StaffMember Stafflist1:Stafflist)
    {
    Stafflist1.toString();
    System.out.println("-----------------------------------------");
    }
    }
    Staff( ){
    StaffMember manager=new Manager("Sam","123 Main Line","555-0469","123-45-6789",2423.07,500);
Stafflist[0]=manager;
    StaffMember employee1=new Employee("Peter","456 Off Line","555-0101","987-65-4321",1246.15);
Stafflist[1]=employee1;
StaffMember employee2=new Employee("Mary","789 Off Rocker","555-0690","010-20-3040",1169.23);
Stafflist[2]=employee2;
StaffMember hourly=new Hourly("Cliff","678 Fifth Ave","555-0000","958-47-3625",10.55,40);
Stafflist[3]=hourly;
StaffMember volunteer1=new Volunteer("Al","987 Suds Ave","555-8374");
Stafflist[4]=volunteer1;
StaffMember volunteer2=new Volunteer("Gus","321 Off Line","555-7282");
Stafflist[5]=volunteer2;
    }
public static void main(String[] args) {
Staff s1=new Staff();
s1.paydatail();


}
}




//定义一个虚类
abstract class StaffMember
{
protected String name;
protected String address;
protected String phone;
public String toString() {
System.out.println("姓名:"+this.name);
System.out.println("地址:"+this.address);
System.out.println("电话:"+this.phone);
return null;

}
public abstract double pay();
}




//定义一个Employee类
class Employee extends StaffMember
{
    protected String socialSN;//社会安全号
    protected double payRade;//基本工资
    Employee(String name,String address,String phone,String socialSN,double payRade){
    this.name=name;
    this.address=address;
    this.phone=phone;
    this.socialSN=socialSN;
    this.payRade=payRade;
    }
@Override
public double pay() {
return payRade;
}
public String toString() {
System.out.println("姓名:"+this.name);
System.out.println("地址:"+this.address);
System.out.println("电话:"+this.phone);
System.out.println("社会安全号:"+this.socialSN);
System.out.println("工资:"+"$"+this.pay());
return null;
}
}


//定义一个Volunteer类
class Volunteer extends StaffMember{
Volunteer(String name,String address,String phone){
    this.name=name;
    this.address=address;
    this.phone=phone;
    }


@Override
public double pay() {
return 0;
}
public String toString() {
System.out.println("姓名:"+this.name);
System.out.println("地址:"+this.address);
System.out.println("电话:"+this.phone);
System.out.println("多谢!");
return null;
}
}


//定义一个Manager类
class Manager extends Employee{
//bonus代表红利;awardBonus方法用来增加红利。
double bonus;
Manager(String name,String address,String phone,String socialSN,double payRade,double bonus){
    super(name,address,phone,socialSN,payRade);
    awardBonus(bonus);
    }
void awardBonus(double bonus)//红利
{
this.bonus=bonus;
}
public double pay()
{
return this.bonus+this.payRade;
}
public String toString() {
System.out.println("姓名:"+this.name);
System.out.println("地址:"+this.address);
System.out.println("电话:"+this.phone);
System.out.println("社会安全号:"+this.socialSN);
System.out.println("工资:"+"$"+this.pay());
return null;
}
}


//定义一个hourly类
class Hourly extends Employee{
int hoursWorked;//月工作的小时数
Hourly(String name, String address, String phone, String socialSN, double payRade,int hoursWorked) {
super(name, address, phone, socialSN, payRade);
this.hoursWorked=hoursWorked;
}
    void addHours(int hours) {
    hoursWorked=this.hoursWorked+hours;
    }
    public double pay()
{
return this.payRade*this.hoursWorked;
}
public String toString() {
System.out.println("姓名:"+this.name);
System.out.println("地址:"+this.address);
System.out.println("电话:"+this.phone);
System.out.println("社会安全号:"+this.socialSN);
System.out.println("工作小时数:"+this.hoursWorked);
System.out.println("工资:"+"$"+this.pay());
return null;
}
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页