编写一个程序来读取员工记录文件,在记录上打印摘要,并列出薪水在给定范围内的员工列表。 应该创建一个 Employee 类来存储记录。应该创建一个 Main 类来处理记录。 要求: Requirements 1: The Employee class 应该 A.包含私人数据成员:名字和姓氏,身份证号和薪水 B.如果需要访问数据成员,则获取方法 C.有合适的构造函数 D.有一种方法可以测试给定范围内的员工薪水 E.覆盖 toString 方法以输出员工的详细信息 3.您的程序应: ·显示为解决方案做出贡献的学生的姓名·将员工记录从文件中读取到数组中 ·显示摘要信息;员工人数,平均薪水,最低薪水以及最高薪水 ·重复 o 向用户询问工资范围 。显示工资在该范围内的所有记录。显示匹配记录的总数
请先说一下你能做到哪个程度,碰到了什么具体问题。
请参考: https://blog.csdn.net/qq_32599479/article/details/90773843
package jxc;
public class Employee {
private String number;
private String name;
private double salary;
private String name1;
private int Id;
private static double minimumSalary;
//无参构造器
public Employee() {
}
//给属性赋值构造函数
public Employee(String name1, String name, int id,double salary) {
super();
this.name1 = name1;
this.name = name;
this.Id=id;
this.salary = salary;
}
public String getName1() {
return name1;
}
public void setName1(String name1) {
this.name1 = name1;
}
public int getId() {
return Id;
}
public void setName1(int Id) {
this.Id = Id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
if (salary > minimumSalary) {
this.salary = salary;
} else {
this.salary = minimumSalary;
}
}
@Override
public String toString() {
return "Employee [name1=" + name1 + ", name=" + name + ",ID="+Id+", salary=" +
salary + "]";
}
}
package jxc;
import java.io.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) {
Employee e2 = new Employee();
e2.setName("小二");
e2.setName1("王");
e2.setSalary(5500.1);
System.out.println("员工二:" + e2);
File file = new File("D:\\Html文件\\a1.txt");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
// 创建输入流对象
BufferedReader bReader = new BufferedReader(new FileReader("D:\\\\Html文件\\\\a1.txt"));
// 创建输出流对象
BufferedWriter bWriter = new BufferedWriter(new OutputStreamWriter(System.out));
// 进行数据的读写
String lineString;// 存储数据
while ((lineString = bReader.readLine()) != null) {
bWriter.write(lineString);
bWriter.newLine();
}
// 释放资源
bWriter.close();
bReader.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}