-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw11_hw05_hw49.java
115 lines (109 loc) · 2.77 KB
/
w11_hw05_hw49.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.io.*;
import java.util.regex.Pattern;
class w11_hw05_hw49 {
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String name, telephone, skill;
int year, salary;
System.out.print("請輸入工程師姓名:");
name = buf.readLine();
System.out.print("請輸入工程師手機:");
telephone = buf.readLine();
System.out.print("謮輸入工程師年資:");
year = Integer.parseInt(buf.readLine());
System.out.print("謮輸入工程師薪水:");
salary = Integer.parseInt(buf.readLine());
System.out.print("請輸入工程師專長:");
skill = buf.readLine();
Engineer e1 = new Engineer(name, telephone, year, salary, skill);
e1.showProfile();
}
}
class Engineer extends Employee {
private String skill;
private int salary;
Engineer(String name, String telephone, int year, int salary, String skill) {
set_name(name);
set_telephone(telephone);
set_year(year);
set_salary(salary);
set_skill(skill);
}
public void set_skill(String skill) {
this.skill = skill;
}
public void set_salary(int salary) {
this.salary = salary;
}
public String get_skill() {
return skill;
}
public int get_salary() {
return salary;
}
private int getYearSalary() {
int year = get_year();
if (year <= 5) {
return (int)(salary * 12 * 1.1);
} else if (year <= 15) {
return (int)(salary * 12 * 1.2);
} else if (year <= 25) {
return (int)(salary * 12 * 1.3);
} else {
return (int)(salary * 12 * 1.4);
}
}
public void showProfile() {
System.out.println("工程師姓名:"+get_name());
System.out.println("工程師手機:"+get_telephone());
System.out.println("工程師年資:"+get_year());
System.out.println("工程師薪水:"+salary);
System.out.println("工程師專長:"+skill);
System.out.println("工程師年薪:"+getYearSalary());
}
}
class Employee {
private String name, telephone;
private int year;
Employee() {
this("", "", 1);
}
Employee(String name, String telephone, int year) {
set_name(name);
set_telephone(telephone);
set_year(year);
}
public void set_name(String name) {
this.name = name;
}
public void set_telephone(String telephone) {
if (telephone.matches("09\\d{8}")) {
this.telephone = telephone;
} else {
this.telephone = "0912345678";
}
}
public void set_year(int year) {
if (year < 1) {
this.year = 1;
} else if (year > 30) {
this.year = 1;
} else {
this.year = year;
}
}
public String get_name() {
return name;
}
public String get_telephone() {
return telephone;
}
public int get_year() {
return year;
}
public void showProfile() {
System.out.println("員工姓名:"+name);
System.out.println("員工手機:"+telephone);
System.out.println("員工年資:"+year);
}
}