定義一個教師類(姓名、工齡、職稱),提供計算工資的方法,工資=基礎工資+工齡工資。職稱工資標準爲:初級2000元、中級3000元、高級5000元;工齡工資標準爲100元/年。
Teacher類
public class Teacher {
private String name;//姓名
private int age;//工齡
private String title;//職稱
public double endWage(String name,int age,String title){
double wage = 0;
if (title.equals("普通")){
wage = 3000+age*50;
System.out.println(wage);
}
if (title.equals("高級")){
wage = 5000+age*50;
System.out.println(wage);
}
if (title.equals("特級")){
wage = 8000+age*50;
System.out.println(wage);
}
return wage;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return "Teacher{" +
"name='" + name + '\'' +
", age=" + age +
", title='" + title + '\'' +
'}';
}
}
Test類
public class Test {
public static void main(String[] args) {
Teacher tach = new Teacher();
tach.setName("子明");
tach.setAge(4);
tach.setTitle("特級");
tach.endWage("子明",4,"特級");
System.out.println(tach.toString());
}
}