java 员工管理系统 向文本文件中备份
2015-09-16 13:37
501 查看
package emp;
//顶级父类
import java.util.*;
public class emper {
String id;
String name;
String posi;
int holiday;
double salary;
public emper(String id,String name,String posi,int holiday,double salary){
this.id = id;
this.name = name;
this.posi = posi;
this.holiday = holiday;
this.salary = salary;
}
public String getName(){
return this.name;
}
public double sumSalary(){
return 0.00;
}
public String toString(){
return "编号:"+id+" 名字:"+name+ " 职位:"+posi
+" 请假天数:"+holiday+" 工资:"+ sumSalary();
}
}
//普通员工
package emp;
import java.util.*;
public class commonEmployee extends emper{
public commonEmployee(String id,String name,String posi,int holiday,double salary){
super(id, name, posi, holiday, salary);
}
public double sumSalary(){
return (this.salary*1.6+200)-(salary/30*holiday);
}
}
//经理
package emp;
import java.util.*;
public class Manager extends emper{
public Manager(String id,String name,String posi,int holiday,double salary){
super(id, name, posi, holiday, salary);
}
public double sumSalary(){
return (this.salary*1.7+500)-(salary/30*holiday);
}
}
//董事
package emp;
import java.util.*;
public class Director extends emper{
public Director(String id,String name,String posi,int holiday,double salary){
super(id, name, posi, holiday, salary);
}
public double sumSalary(){
return (this.salary*1.38+5000)-(salary/30*holiday);
}
}
//主要的逻辑程序
package emp;
import java.io.*;
import java.util.*;
import com.sun.javafx.geom.AreaOp.AddOp;
public class testEmp {
Scanner sc = new Scanner(System.in);
// 定义查找到的索引
int findex;
String filename = "D:/emp.txt"; //备份文件的储存位置
ArrayList<emper> empList = new ArrayList<emper>();
public void choise() throws IOException {
System.out.println("|------------------|\n|-----1 增加 ------|"
+ "\n|-----2 删除 ------|\n"
+ "|-----3 修改 ------|\n|-----4 查询 ------|"
+ "\n|-----5 备份 ------|\n|-----0 退出 ------|\n|------------------|");
System.out.println("请选择业务");
int mchoise = sc.nextInt();
switch (mchoise) {
case 1:
Add();
System.out.println("添加成功");
break;
case 2:
del();
break;
case 3:
upd();
break;
case 4:
System.out.println("请输入要查找的姓名");
String fname = sc.next();
Find(fname);
break;
case 5:
Writer();
System.out.println("备份完成");
break;
case 0:
System.out.print("退出成功");
Writer();
break;
default:
getAll();
Writer();
break;
}
}
//初始化,将文件内容导入员工 数组
public void init() throws IOException{
//判断d盘下的文件是否存在 ,如果不存在,生成文件
File f1 = new File(filename) ;
if(!f1.exists()){
f1.createNewFile();
System.out.println("文件已生成");
}
BufferedReader br = new BufferedReader(new FileReader(f1));
String rline;
int n = 0;
br.readLine(); //跳过第一行 ;
while((rline = br.readLine()) !=null ){
String[] read = rline.split(",");
empList.add(new emper(read[0],read[1],read[2],Integer.parseInt(read[3]),Double.parseDouble(read[4])) );
}
br.close(); //关闭
System.out.println("初始化成功");
}
//备份
public void Writer() throws IOException {
BufferedWriter bw = new BufferedWriter( new FileWriter("D:/emp.txt") );
bw.write("编号 , 姓名 , 职位 ,请假天数 , 工资");
bw.newLine(); //换行;
for(int w=0;w<empList.size();w++){
String wid = empList.get(w).id;
String wname = empList.get(w).name;
String wposi = empList.get(w).posi;
int wholi = empList.get(w).holiday;
double wsalaery = empList.get(w).sumSalary();
bw.write(wid+","+wname+","+wposi+","+wholi+","+wsalaery);
bw.newLine(); //换行;
}
bw.close();
}
//修改
public void upd() {
System.out.println("请输入你要修改的名字");
String uname = sc.next();
if (Find(uname)) {
System.out.println("请输入员工编号");
String id = sc.next();
System.out.println("请输入员工职务(1 :普通员工, 2:经理, 3:董事)");
String posi = sc.next();
System.out.println("请输入员工请假天数");
int hday = sc.nextInt();
System.out.println("请输入员工基本工资");
double sal = sc.nextDouble();
if (posi.equals("1")) {
empList.set(findex,new commonEmployee(id, uname, "普通员工", hday, sal));
} else if (posi.equals("2")) {
empList.set(findex,new Manager(id, uname, "经理", hday, sal));
} else if (posi.equals("3")) {
empList.set(findex,new Director(id, uname, "董事", hday, sal));
}
System.out.println("修改成功");
System.out.println(empList.get(findex));
} else {
System.out.println("无此纪录");
}
}
//删除
public void del() {
System.out.println("请输入要删除的名字");
String dname = sc.next();
if (Find(dname)) {
empList.remove(findex);
System.out.println("纪录删除成功");
} else {
System.out.println("无此纪录");
}
}
// 增加数据
public void Add() {
System.out.println("请输入员工编号");
String id = sc.next();
System.out.println("请输入员工姓名");
String name = sc.next();
System.out.println("请输入员工职务(1 :普通员工, 2:经理, 3:董事)");
String posi = sc.next();
System.out.println("请输入员工请假天数");
int hday = sc.nextInt();
System.out.println("请输入员工基本工资");
double sal = sc.nextDouble();
if (posi.equals("1")) {
empList.add(new commonEmployee(id, name, "普通员工", hday, sal));
} else if (posi.equals("2")) {
empList.add(new Manager(id, name, "普通员工", hday, sal));
} else if (posi.equals("3")) {
empList.add(new Director(id, name, "普通员工", hday, sal));
}
System.out.println("增加数据成功");
System.out.println(empList.get(empList.size() - 1));
}
// 查全部
public void getAll() {
for (int w = 0; w < empList.size(); w++) {
Object emp = empList.get(w);
System.out.println(emp);
}
}
// 按姓名查找
public boolean Find(String name) {
for (int w = 0; w < empList.size(); w++) {
if (name.equals(empList.get(w).getName())) {
findex = w;
System.out.println(empList.get(w));
return true;
}
}
// System.out.println(empList.get(w));
return false;
}
}
//主程序
package emp;
import java.io.*;
import java.util.*;
import com.sun.javafx.geom.AreaOp.AddOp;
public class testEmp {
Scanner sc = new Scanner(System.in);
// 定义查找到的索引
int findex;
String filename = "D:/emp.txt"; //备份文件的储存位置
ArrayList<emper> empList = new ArrayList<emper>();
public void choise() throws IOException {
System.out.println("|------------------|\n|-----1 增加 ------|"
+ "\n|-----2 删除 ------|\n"
+ "|-----3 修改 ------|\n|-----4 查询 ------|"
+ "\n|-----5 备份 ------|\n|-----0 退出 ------|\n|------------------|");
System.out.println("请选择业务");
int mchoise = sc.nextInt();
switch (mchoise) {
case 1:
Add();
System.out.println("添加成功");
break;
case 2:
del();
break;
case 3:
upd();
break;
case 4:
System.out.println("请输入要查找的姓名");
String fname = sc.next();
Find(fname);
break;
case 5:
Writer();
System.out.println("备份完成");
break;
case 0:
System.out.print("退出成功");
Writer();
break;
default:
getAll();
Writer();
break;
}
}
//初始化,将文件内容导入员工 数组
public void init() throws IOException{
//判断d盘下的文件是否存在 ,如果不存在,生成文件
File f1 = new File(filename) ;
if(!f1.exists()){
f1.createNewFile();
System.out.println("文件已生成");
}
BufferedReader br = new BufferedReader(new FileReader(f1));
String rline;
int n = 0;
br.readLine(); //跳过第一行 ;
while((rline = br.readLine()) !=null ){
String[] read = rline.split(",");
empList.add(new emper(read[0],read[1],read[2],Integer.parseInt(read[3]),Double.parseDouble(read[4])) );
}
br.close(); //关闭
System.out.println("初始化成功");
}
//备份
public void Writer() throws IOException {
BufferedWriter bw = new BufferedWriter( new FileWriter("D:/emp.txt") );
bw.write("编号 , 姓名 , 职位 ,请假天数 , 工资");
bw.newLine(); //换行;
for(int w=0;w<empList.size();w++){
String wid = empList.get(w).id;
String wname = empList.get(w).name;
String wposi = empList.get(w).posi;
int wholi = empList.get(w).holiday;
double wsalaery = empList.get(w).sumSalary();
bw.write(wid+","+wname+","+wposi+","+wholi+","+wsalaery);
bw.newLine(); //换行;
}
bw.close();
}
//修改
public void upd() {
System.out.println("请输入你要修改的名字");
String uname = sc.next();
if (Find(uname)) {
System.out.println("请输入员工编号");
String id = sc.next();
System.out.println("请输入员工职务(1 :普通员工, 2:经理, 3:董事)");
String posi = sc.next();
System.out.println("请输入员工请假天数");
int hday = sc.nextInt();
System.out.println("请输入员工基本工资");
double sal = sc.nextDouble();
if (posi.equals("1")) {
empList.set(findex,new commonEmployee(id, uname, "普通员工", hday, sal));
} else if (posi.equals("2")) {
empList.set(findex,new Manager(id, uname, "经理", hday, sal));
} else if (posi.equals("3")) {
empList.set(findex,new Director(id, uname, "董事", hday, sal));
}
System.out.println("修改成功");
System.out.println(empList.get(findex));
} else {
System.out.println("无此纪录");
}
}
//删除
public void del() {
System.out.println("请输入要删除的名字");
String dname = sc.next();
if (Find(dname)) {
empList.remove(findex);
System.out.println("纪录删除成功");
} else {
System.out.println("无此纪录");
}
}
// 增加数据
public void Add() {
System.out.println("请输入员工编号");
String id = sc.next();
System.out.println("请输入员工姓名");
String name = sc.next();
System.out.println("请输入员工职务(1 :普通员工, 2:经理, 3:董事)");
String posi = sc.next();
System.out.println("请输入员工请假天数");
int hday = sc.nextInt();
System.out.println("请输入员工基本工资");
double sal = sc.nextDouble();
if (posi.equals("1")) {
empList.add(new commonEmployee(id, name, "普通员工", hday, sal));
} else if (posi.equals("2")) {
empList.add(new Manager(id, name, "普通员工", hday, sal));
} else if (posi.equals("3")) {
empList.add(new Director(id, name, "普通员工", hday, sal));
}
System.out.println("增加数据成功");
System.out.println(empList.get(empList.size() - 1));
}
// 查全部
public void getAll() {
for (int w = 0; w < empList.size(); w++) {
Object emp = empList.get(w);
System.out.println(emp);
}
}
// 按姓名查找
public boolean Find(String name) {
for (int w = 0; w < empList.size(); w++) {
if (name.equals(empList.get(w).getName())) {
findex = w;
System.out.println(empList.get(w));
return true;
}
}
// System.out.println(empList.get(w));
return false;
}
}
//顶级父类
import java.util.*;
public class emper {
String id;
String name;
String posi;
int holiday;
double salary;
public emper(String id,String name,String posi,int holiday,double salary){
this.id = id;
this.name = name;
this.posi = posi;
this.holiday = holiday;
this.salary = salary;
}
public String getName(){
return this.name;
}
public double sumSalary(){
return 0.00;
}
public String toString(){
return "编号:"+id+" 名字:"+name+ " 职位:"+posi
+" 请假天数:"+holiday+" 工资:"+ sumSalary();
}
}
//普通员工
package emp;
import java.util.*;
public class commonEmployee extends emper{
public commonEmployee(String id,String name,String posi,int holiday,double salary){
super(id, name, posi, holiday, salary);
}
public double sumSalary(){
return (this.salary*1.6+200)-(salary/30*holiday);
}
}
//经理
package emp;
import java.util.*;
public class Manager extends emper{
public Manager(String id,String name,String posi,int holiday,double salary){
super(id, name, posi, holiday, salary);
}
public double sumSalary(){
return (this.salary*1.7+500)-(salary/30*holiday);
}
}
//董事
package emp;
import java.util.*;
public class Director extends emper{
public Director(String id,String name,String posi,int holiday,double salary){
super(id, name, posi, holiday, salary);
}
public double sumSalary(){
return (this.salary*1.38+5000)-(salary/30*holiday);
}
}
//主要的逻辑程序
package emp;
import java.io.*;
import java.util.*;
import com.sun.javafx.geom.AreaOp.AddOp;
public class testEmp {
Scanner sc = new Scanner(System.in);
// 定义查找到的索引
int findex;
String filename = "D:/emp.txt"; //备份文件的储存位置
ArrayList<emper> empList = new ArrayList<emper>();
public void choise() throws IOException {
System.out.println("|------------------|\n|-----1 增加 ------|"
+ "\n|-----2 删除 ------|\n"
+ "|-----3 修改 ------|\n|-----4 查询 ------|"
+ "\n|-----5 备份 ------|\n|-----0 退出 ------|\n|------------------|");
System.out.println("请选择业务");
int mchoise = sc.nextInt();
switch (mchoise) {
case 1:
Add();
System.out.println("添加成功");
break;
case 2:
del();
break;
case 3:
upd();
break;
case 4:
System.out.println("请输入要查找的姓名");
String fname = sc.next();
Find(fname);
break;
case 5:
Writer();
System.out.println("备份完成");
break;
case 0:
System.out.print("退出成功");
Writer();
break;
default:
getAll();
Writer();
break;
}
}
//初始化,将文件内容导入员工 数组
public void init() throws IOException{
//判断d盘下的文件是否存在 ,如果不存在,生成文件
File f1 = new File(filename) ;
if(!f1.exists()){
f1.createNewFile();
System.out.println("文件已生成");
}
BufferedReader br = new BufferedReader(new FileReader(f1));
String rline;
int n = 0;
br.readLine(); //跳过第一行 ;
while((rline = br.readLine()) !=null ){
String[] read = rline.split(",");
empList.add(new emper(read[0],read[1],read[2],Integer.parseInt(read[3]),Double.parseDouble(read[4])) );
}
br.close(); //关闭
System.out.println("初始化成功");
}
//备份
public void Writer() throws IOException {
BufferedWriter bw = new BufferedWriter( new FileWriter("D:/emp.txt") );
bw.write("编号 , 姓名 , 职位 ,请假天数 , 工资");
bw.newLine(); //换行;
for(int w=0;w<empList.size();w++){
String wid = empList.get(w).id;
String wname = empList.get(w).name;
String wposi = empList.get(w).posi;
int wholi = empList.get(w).holiday;
double wsalaery = empList.get(w).sumSalary();
bw.write(wid+","+wname+","+wposi+","+wholi+","+wsalaery);
bw.newLine(); //换行;
}
bw.close();
}
//修改
public void upd() {
System.out.println("请输入你要修改的名字");
String uname = sc.next();
if (Find(uname)) {
System.out.println("请输入员工编号");
String id = sc.next();
System.out.println("请输入员工职务(1 :普通员工, 2:经理, 3:董事)");
String posi = sc.next();
System.out.println("请输入员工请假天数");
int hday = sc.nextInt();
System.out.println("请输入员工基本工资");
double sal = sc.nextDouble();
if (posi.equals("1")) {
empList.set(findex,new commonEmployee(id, uname, "普通员工", hday, sal));
} else if (posi.equals("2")) {
empList.set(findex,new Manager(id, uname, "经理", hday, sal));
} else if (posi.equals("3")) {
empList.set(findex,new Director(id, uname, "董事", hday, sal));
}
System.out.println("修改成功");
System.out.println(empList.get(findex));
} else {
System.out.println("无此纪录");
}
}
//删除
public void del() {
System.out.println("请输入要删除的名字");
String dname = sc.next();
if (Find(dname)) {
empList.remove(findex);
System.out.println("纪录删除成功");
} else {
System.out.println("无此纪录");
}
}
// 增加数据
public void Add() {
System.out.println("请输入员工编号");
String id = sc.next();
System.out.println("请输入员工姓名");
String name = sc.next();
System.out.println("请输入员工职务(1 :普通员工, 2:经理, 3:董事)");
String posi = sc.next();
System.out.println("请输入员工请假天数");
int hday = sc.nextInt();
System.out.println("请输入员工基本工资");
double sal = sc.nextDouble();
if (posi.equals("1")) {
empList.add(new commonEmployee(id, name, "普通员工", hday, sal));
} else if (posi.equals("2")) {
empList.add(new Manager(id, name, "普通员工", hday, sal));
} else if (posi.equals("3")) {
empList.add(new Director(id, name, "普通员工", hday, sal));
}
System.out.println("增加数据成功");
System.out.println(empList.get(empList.size() - 1));
}
// 查全部
public void getAll() {
for (int w = 0; w < empList.size(); w++) {
Object emp = empList.get(w);
System.out.println(emp);
}
}
// 按姓名查找
public boolean Find(String name) {
for (int w = 0; w < empList.size(); w++) {
if (name.equals(empList.get(w).getName())) {
findex = w;
System.out.println(empList.get(w));
return true;
}
}
// System.out.println(empList.get(w));
return false;
}
}
//主程序
package emp;
import java.io.*;
import java.util.*;
import com.sun.javafx.geom.AreaOp.AddOp;
public class testEmp {
Scanner sc = new Scanner(System.in);
// 定义查找到的索引
int findex;
String filename = "D:/emp.txt"; //备份文件的储存位置
ArrayList<emper> empList = new ArrayList<emper>();
public void choise() throws IOException {
System.out.println("|------------------|\n|-----1 增加 ------|"
+ "\n|-----2 删除 ------|\n"
+ "|-----3 修改 ------|\n|-----4 查询 ------|"
+ "\n|-----5 备份 ------|\n|-----0 退出 ------|\n|------------------|");
System.out.println("请选择业务");
int mchoise = sc.nextInt();
switch (mchoise) {
case 1:
Add();
System.out.println("添加成功");
break;
case 2:
del();
break;
case 3:
upd();
break;
case 4:
System.out.println("请输入要查找的姓名");
String fname = sc.next();
Find(fname);
break;
case 5:
Writer();
System.out.println("备份完成");
break;
case 0:
System.out.print("退出成功");
Writer();
break;
default:
getAll();
Writer();
break;
}
}
//初始化,将文件内容导入员工 数组
public void init() throws IOException{
//判断d盘下的文件是否存在 ,如果不存在,生成文件
File f1 = new File(filename) ;
if(!f1.exists()){
f1.createNewFile();
System.out.println("文件已生成");
}
BufferedReader br = new BufferedReader(new FileReader(f1));
String rline;
int n = 0;
br.readLine(); //跳过第一行 ;
while((rline = br.readLine()) !=null ){
String[] read = rline.split(",");
empList.add(new emper(read[0],read[1],read[2],Integer.parseInt(read[3]),Double.parseDouble(read[4])) );
}
br.close(); //关闭
System.out.println("初始化成功");
}
//备份
public void Writer() throws IOException {
BufferedWriter bw = new BufferedWriter( new FileWriter("D:/emp.txt") );
bw.write("编号 , 姓名 , 职位 ,请假天数 , 工资");
bw.newLine(); //换行;
for(int w=0;w<empList.size();w++){
String wid = empList.get(w).id;
String wname = empList.get(w).name;
String wposi = empList.get(w).posi;
int wholi = empList.get(w).holiday;
double wsalaery = empList.get(w).sumSalary();
bw.write(wid+","+wname+","+wposi+","+wholi+","+wsalaery);
bw.newLine(); //换行;
}
bw.close();
}
//修改
public void upd() {
System.out.println("请输入你要修改的名字");
String uname = sc.next();
if (Find(uname)) {
System.out.println("请输入员工编号");
String id = sc.next();
System.out.println("请输入员工职务(1 :普通员工, 2:经理, 3:董事)");
String posi = sc.next();
System.out.println("请输入员工请假天数");
int hday = sc.nextInt();
System.out.println("请输入员工基本工资");
double sal = sc.nextDouble();
if (posi.equals("1")) {
empList.set(findex,new commonEmployee(id, uname, "普通员工", hday, sal));
} else if (posi.equals("2")) {
empList.set(findex,new Manager(id, uname, "经理", hday, sal));
} else if (posi.equals("3")) {
empList.set(findex,new Director(id, uname, "董事", hday, sal));
}
System.out.println("修改成功");
System.out.println(empList.get(findex));
} else {
System.out.println("无此纪录");
}
}
//删除
public void del() {
System.out.println("请输入要删除的名字");
String dname = sc.next();
if (Find(dname)) {
empList.remove(findex);
System.out.println("纪录删除成功");
} else {
System.out.println("无此纪录");
}
}
// 增加数据
public void Add() {
System.out.println("请输入员工编号");
String id = sc.next();
System.out.println("请输入员工姓名");
String name = sc.next();
System.out.println("请输入员工职务(1 :普通员工, 2:经理, 3:董事)");
String posi = sc.next();
System.out.println("请输入员工请假天数");
int hday = sc.nextInt();
System.out.println("请输入员工基本工资");
double sal = sc.nextDouble();
if (posi.equals("1")) {
empList.add(new commonEmployee(id, name, "普通员工", hday, sal));
} else if (posi.equals("2")) {
empList.add(new Manager(id, name, "普通员工", hday, sal));
} else if (posi.equals("3")) {
empList.add(new Director(id, name, "普通员工", hday, sal));
}
System.out.println("增加数据成功");
System.out.println(empList.get(empList.size() - 1));
}
// 查全部
public void getAll() {
for (int w = 0; w < empList.size(); w++) {
Object emp = empList.get(w);
System.out.println(emp);
}
}
// 按姓名查找
public boolean Find(String name) {
for (int w = 0; w < empList.size(); w++) {
if (name.equals(empList.get(w).getName())) {
findex = w;
System.out.println(empList.get(w));
return true;
}
}
// System.out.println(empList.get(w));
return false;
}
}
相关文章推荐
- Spring注解开发
- JDK 动态代理
- JAVA一个超级简单的计算器
- eclipse插件
- java中注解的使用与实例
- Java与C#的区别
- MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合
- Java Socket 与飞秋 通信
- Spring+Spring MVC+Hibernate环境搭配
- 【Java EE 学习 44】【Hibernate学习第一天】【Hibernate对单表的CRUD操作】
- 详细解析Java中抽象类和接口的区别
- java中的堆、栈、常量池
- SpringMVC之访问静态文件
- Java JVM(十一):MAT 工具的使用
- 简易计算器NetBeans Ide
- java学习之JDK5新特性
- java中文件的I/O操作
- java学习之Math类
- java学习之泛型
- SpringMVC实现一个controller写多个方法