java抽象方法练习

Employee

package 抽象方法练习;

public abstract class Employee {
	private String name;
	private	int number;
	private Mydate birthday;
	
	public Employee(String name, int number, Mydate birthday) {
		super();
		this.name = name;
		this.number = number;
		this.birthday = birthday;
	}

	public abstract double earnings();
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public Mydate getBirthday() {
		return birthday;
	}

	public void setBirthday(Mydate birthday) {
		this.birthday = birthday;
	}

	public String toString() {
		return " 姓名:" + name + " 工号:" + number + " 生日:" + birthday.toDateString();
	}

	
}

Mydate

package 抽象方法练习;

public class Mydate {
	private int year;
	private int month;
	private int day;
	

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getDay() {
		return day;
	}

	public void setDay(int day) {
		this.day = day;
	}

	public Mydate(int year, int month, int day) {
		super();
		this.year = year;
		this.month = month;
		this.day = day;
	}

	public String toDateString() {
		return year + "年" + month + "月" + day + "日";
	}
	
}

HourlyEmployee

package 抽象方法练习;

public class HourlyEmployee extends Employee {
	
	private double wage;
	private int hour;
	
	public double getWage() {
		return wage;
	}

	public void setWage(double wage) {
		this.wage = wage;
	}

	public int getHour() {
		return hour;
	}

	public void setHour(int hour) {
		this.hour = hour;
	}

	public HourlyEmployee(String name, int number, Mydate birthday,double wage,int hour) {
		super(name, number, birthday);
		this.hour = hour;
		this.wage = wage;
	}
	
	public double earnings() {
		return wage * hour;
	}
	
	public String toString() {
		return "类型:HourlyEmployee " + super.toString();
	}

}

SalariedEmployee

package 抽象方法练习;

public class SalariedEmployee extends Employee {
	private double monthlySalary;

	
	public double getMonthlySalary() {
		return monthlySalary;
	}

	public void setMonthlySalary(double monthlySalary) {
		this.monthlySalary = monthlySalary;
	}

	public SalariedEmployee(String name, int number, Mydate birthday, double monthlySalary) {
		super(name, number, birthday);
		this.monthlySalary = monthlySalary;
	}

	public double earnings() {
		return monthlySalary;
	}

	public String toString() {
		return "类型:SalariedEmployee " + super.toString();
	}

}

PayrollSystem

package 抽象方法练习;

import java.util.Scanner;

public class PayrollSystem {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		System.out.println("请输入当前月份:");
		int m = scan.nextInt();
		
		Employee e[]=new Employee[2];
		e[0] = new SalariedEmployee("ljl", 1001, new Mydate(1999, 8, 8), 15000);
		e[1] = new HourlyEmployee("wy", 2001, new Mydate(2000, 2, 14), 60, 240);
		
		for(int i = 0; i < e.length;i++) {
			System.out.println(e[i].toString());
			System.out.println(e[i].getName() + "的月工资为 " +e[i].earnings() );
			if(m == e[i].getBirthday().getMonth())
				System.out.println(e[i].getName() + "生日快乐,奖励100元");	
		}
	}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值