Compare commits
3 Commits
c9250ab71d
...
910207cd75
| Author | SHA1 | Date |
|---|---|---|
|
|
910207cd75 | 3 weeks ago |
|
|
847cd354ee | 3 weeks ago |
|
|
b03973c341 | 3 weeks ago |
10 changed files with 190 additions and 0 deletions
@ -0,0 +1,30 @@ |
|||
### IntelliJ IDEA ### |
|||
out/ |
|||
!**/src/main/**/out/ |
|||
!**/src/test/**/out/ |
|||
.kotlin |
|||
|
|||
### Eclipse ### |
|||
.apt_generated |
|||
.classpath |
|||
.factorypath |
|||
.project |
|||
.settings |
|||
.springBeans |
|||
.sts4-cache |
|||
bin/ |
|||
!**/src/main/**/bin/ |
|||
!**/src/test/**/bin/ |
|||
|
|||
### NetBeans ### |
|||
/nbproject/private/ |
|||
/nbbuild/ |
|||
/dist/ |
|||
/nbdist/ |
|||
/.nb-gradle/ |
|||
|
|||
### VS Code ### |
|||
.vscode/ |
|||
|
|||
### Mac OS ### |
|||
.DS_Store |
|||
@ -0,0 +1,10 @@ |
|||
# Default ignored files |
|||
/shelf/ |
|||
/workspace.xml |
|||
# Ignored default folder with query files |
|||
/queries/ |
|||
# Datasource local storage ignored files |
|||
/dataSources/ |
|||
/dataSources.local.xml |
|||
# Editor-based HTTP Client requests |
|||
/httpRequests/ |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK"> |
|||
<output url="file://$PROJECT_DIR$/out" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,8 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="ProjectModuleManager"> |
|||
<modules> |
|||
<module fileurl="file://$PROJECT_DIR$/untitled1.iml" filepath="$PROJECT_DIR$/untitled1.iml" /> |
|||
</modules> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="VcsDirectoryMappings"> |
|||
<mapping directory="$PROJECT_DIR$" vcs="Git" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,15 @@ |
|||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
|||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
|||
public class Main { |
|||
public static void main(String[] args) { |
|||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
|||
// to see how IntelliJ IDEA suggests fixing it.
|
|||
System.out.printf("Hello and welcome!"); |
|||
|
|||
for (int i = 1; i <= 5; i++) { |
|||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
|||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
|||
System.out.println("i = " + i); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
package w3; |
|||
|
|||
public class Employee { |
|||
// 静态变量:公司名称
|
|||
public static String companyName; |
|||
|
|||
// 成员变量
|
|||
private String id; // 工号
|
|||
private String name; // 姓名
|
|||
private String department;// 部门
|
|||
private double salary; // 工资
|
|||
|
|||
// 最低工资标准
|
|||
private static final double MIN_SALARY = 2000; |
|||
|
|||
// 构造方法:创建对象时赋值
|
|||
public Employee(String id, String name, String department, double salary) { |
|||
this.id = id; |
|||
this.name = name; |
|||
this.department = department; |
|||
setSalary(salary); // 调用方法保证工资合法
|
|||
} |
|||
|
|||
// get/set 方法
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(String id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getDepartment() { |
|||
return department; |
|||
} |
|||
|
|||
public void setDepartment(String department) { |
|||
this.department = department; |
|||
} |
|||
|
|||
public double getSalary() { |
|||
return salary; |
|||
} |
|||
|
|||
public void setSalary(double salary) { |
|||
if (salary >= MIN_SALARY) { |
|||
this.salary = salary; |
|||
} else { |
|||
this.salary = MIN_SALARY; |
|||
System.out.println("工资过低,自动调整为:" + MIN_SALARY); |
|||
} |
|||
} |
|||
|
|||
// 涨薪方法
|
|||
public void raiseSalary(double percent) { |
|||
double newSalary = salary * (1 + percent / 100); |
|||
setSalary(newSalary); |
|||
} |
|||
|
|||
// 打印信息
|
|||
@Override |
|||
public String toString() { |
|||
return "员工{" + |
|||
"公司='" + companyName + '\'' + |
|||
", 工号='" + id + '\'' + |
|||
", 姓名='" + name + '\'' + |
|||
", 部门='" + department + '\'' + |
|||
", 工资=" + salary + |
|||
'}'; |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,24 @@ |
|||
package w3; |
|||
|
|||
public class TestEmployee { |
|||
public static void main(String[] args) { |
|||
// 1. 设置公司名称(静态变量)
|
|||
Employee.companyName = "湖南科技有限公司"; |
|||
|
|||
// 2. 创建两个员工对象
|
|||
Employee emp1 = new Employee("E001", "张三", "技术部", 2500); |
|||
Employee emp2 = new Employee("E002", "李四", "人事部", 1800); |
|||
|
|||
// 3. 打印信息
|
|||
System.out.println(emp1); |
|||
System.out.println(emp2); |
|||
|
|||
// 4. 涨薪
|
|||
emp1.raiseSalary(5); |
|||
emp2.raiseSalary(10); |
|||
System.out.println("\n=====涨薪后====="); |
|||
System.out.println(emp1); |
|||
System.out.println(emp2); |
|||
} |
|||
} |
|||
|
|||
|
After Width: | Height: | Size: 83 KiB |
@ -0,0 +1,11 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<module type="JAVA_MODULE" version="4"> |
|||
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
|||
<exclude-output /> |
|||
<content url="file://$MODULE_DIR$"> |
|||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
|||
</content> |
|||
<orderEntry type="inheritedJdk" /> |
|||
<orderEntry type="sourceFolder" forTests="false" /> |
|||
</component> |
|||
</module> |
|||
Loading…
Reference in new issue