⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gongzi.java

📁 一些刚开始学习JAVA时候的小代码
💻 JAVA
字号:
//p322上机
abstract class Employee{
	String name;
	double basic;
	String address;
	Employee(){
	}
	Employee(String str,double sal,String addr){
		name=str;
		basic=sal;
		address=addr;
	}
	void show(){
		System.out.println("姓名:\t\t\t"+name);
		System.out.println("地址:\t\t\t"+address);
		System.out.println("薪资:\t\t\t"+basic);
	}
	//定义该抽象方法来计算薪资总额
 	abstract double totalAmount();
 
 	//定义方法kouchu来基于天数计算要从基本薪资中扣除的部分
 	double kouchu(int leave,double basic){
		double lessPay;
		return (leave<=5)?(0.25*basic):(0.5*basic);
 }

}
class Manager extends Employee{
	String department;
	Manager(){
	}
	Manager(String str,double sal,String addr,String dept){
		super(str,sal,addr);
		department=dept;
	}
	   //重写父类的totalAmount方法
	double totalAmount(){
		double houseRentAllowance=0.08*basic;
		double dearnessAllowance=0.3*basic;
		int  medicalAllowance=1500;
		double totalAmount=basic+houseRentAllowance+dearnessAllowance+medicalAllowance;
		return totalAmount;
	}

	void show(){
		super.show();
		System.out.println("部门:\t\t\t"+department);
		System.out.println("工资总额\t\t"+this.totalAmount());
		System.out.println("净工资:\t\t\t"+(this.totalAmount()-this.kouchu(5,5500.65)));
	}
}
class Director extends Employee{
	double transportAllowance;
	Director(){
	}
	Director(String str,double sal,String addr,double allowance){
		super(str,sal,addr);
		transportAllowance=allowance;
	}
	double totalAmount(){
		double houseRentAllowance=0.2*basic;
		double dearnessAllowance=0.5*basic;
		int  medicalAllowance=4500;
		int entertainmentAllwance=5000;
		double totalAmount=basic+houseRentAllowance+dearnessAllowance+medicalAllowance+entertainmentAllwance+transportAllowance;
		return totalAmount;
	}

	void show(){
		super.show();
		System.out.println("交通津贴:\t\t"+transportAllowance);
		System.out.println("工资总额:\t\t"+this.totalAmount());
		System.out.println("净工资:\t\t\t"+(this.totalAmount()-this.kouchu(5,32400.00)));
	}
}
class EmployeeTest{
	EmployeeTest(){
	}
	public static void main(String[] args){
		Manager mgrObj= new Manager("Henry",5500.65,"Sydney","会计部");
		System.out.println("\n经理详细信息");
		System.out.println("=============================");
		mgrObj.show();
		Director dirObj=new Director("Stiphen",32400.00,"New York",8000);
		System.out.println("\n\n经理详细信息");
		System.out.println("=============================");
		dirObj.show();			
		}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -