1. 程式人生 > >java練習--輸出員工資訊並計算員工的工資

java練習--輸出員工資訊並計算員工的工資

部門類:
public class Department {
String id;
String name;
public void Department(){
	System.out.println("部門資訊\t部門編號:"+id+",部門名稱:"+name);
	
}
}
員工類:
public class Employee {
	String id1;
	String name2;
	double Salary;
	String name3;

	public void show() {

		Scanner input = new Scanner(System.in);
		System.out.println("員工資訊\t員工編號:" + id1 + ",姓名" + name2 + ",底薪" + Salary
				+ ",所在部門:" + name3);
	}

	public double countSalary(double sales) {
		double x = 0;
		if (sales < 100000) {
			x = Salary + sales * 0.01;
			System.out.println(name2 + "本月的工資為" + x + "元");

		} else if (sales > 100000 && sales < 200000) {
			x = Salary + sales * 0.02;
			System.out.println(name2 + "本月的工資為:" + x + "元");
		} else if (sales >= 200000) {
			x = Salary + sales * 0.03;
			System.out.println(name2 + "本月的工資為:" + x + "元");
		} else {
			System.out.println("輸入錯誤!");
		}
		return x;
	}

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		Department d = new Department();
		d.id = "0001";
		d.name = "銷售部";
		d.Department();
		Employee e = new Employee();
		e.id1 = "0033";
		e.name2 = "郭德綱";
		e.Salary = 2000;
		e.name3 = "銷售部";
		e.show();
		System.out.println("請輸入" + e.name2 + "本月的銷售額:");
		double sales = input.nextDouble();
		e.countSalary(sales);
	}
}