当前位置:编程学习 > JAVA >>

我想知道删除和修改怎么写!


import java.util.Scanner;
/**

 * @author Administrator
 *员工的工资排序
 */
public class Zhishu {

public static String[][] employees= new String[50][];
public static int empCount = 4;//存放有效员工个数

/**
 * @param args
 */
public static void main(String[] args) {

String[] emp1 = new String[]{"001","jack","3500","培训部"};
String[] emp2 = new String[]{"002","tom","4500","培训部"};
String[] emp3 = new String[]{"003","jerry","6500","培训部"};
String[] emp4 = new String[]{"004","lili","5500","培训部"};

employees[0] = emp1;
employees[1] = emp2;
employees[2] = emp3;
employees[3] = emp4;



Scanner sc = new Scanner(System.in);
int choice = 0;
boolean flag = true;

System.out.println("\t\t员工管理系统V1.0\n\n");
System.out.println("\t\t1.添加员工\n");
System.out.println("\t\t2.修改员工\n");
System.out.println("\t\t3.查看所有员工信息\n");
System.out.println("\t\t4.查看单个员工信息\n");
System.out.println("\t\t5.删除员工\n");
System.out.println("\t\t6.排序\n");
System.out.println("请选择操作:");

while (flag) {

try {
sc = new Scanner(System.in);
choice = sc.nextInt();

switch (choice) {
case 0:
System.out.println("\t\t员工管理系统V1.0\n\n");
System.out.println("\t\t1.添加员工\n");
System.out.println("\t\t2.修改员工\n");
System.out.println("\t\t3.查看所有员工信息\n");
System.out.println("\t\t4.查看单个员工信息\n");
System.out.println("\t\t5.删除员工\n");
System.out.println("\t\t6.排序\n");
System.out.println("\t\t7.注销\n");
System.out.println("请选择操作:");
flag = true;
break;
case 1:
//添加员工
//从键盘输入员工信息
sc = new Scanner(System.in);
System.out.println("请输入员工号:");
String empNo = sc.nextLine();
System.out.println("请输入员工姓名:");
String empName = sc.nextLine();
System.out.println("请输入员工工资:");
String empSalary = sc.nextLine();
System.out.println("请输入员工部门:");
String empDept = sc.nextLine();

String[] tempEmp = new String[]{empNo,empName,empSalary,empDept};//得到一个员工信息的一维数组
employees[empCount] = tempEmp;
empCount++;
//显示添加成功,把所有员工信息显示以下
System.out.println("添加成功,员工信息更新为:");
System.out.println("\t\t编号\t姓名\t工资\t部门\t");
for (int i = 0; i < empCount; i++) {
// if(employees[i]==null)
// break;

System.out.println("\t\t"+employees[i][0]+//编号
"\t"+employees[i][1]+
"\t"+employees[i][2]+
"\t"+employees[i][3]+
"\t\n");

}
System.out.println("按0键返回主菜单-->");

flag = true;
break;

case 2:
System.out.println("修改");
flag = true;
break;

case 3:
//查看所有员工信息
System.out.println("\t\t编号\t姓名\t工资\t部门\t");
for (int i = 0; i < empCount; i++) {
// if(employees[i]==null)
// break;

System.out.println("\t\t"+employees[i][0]+//编号
"\t"+employees[i][1]+
"\t"+employees[i][2]+
"\t"+employees[i][3]+
"\t\n");

}
flag = true;

System.out.println("按0键返回主菜单-->");

break;

case 4:
System.out.println("查找");
System.out.println("输入你要查看的员工号");
int d = sc.nextInt();
for (int i = 0; i < empCount; i++) {

int a1=Integer.parseInt(employees[i][0]);
if(a1==d){
System.out.println("\t\t编号\t姓名\t工资\t部门\t");
System.out.println("\t\t"+employees[i][0]+//编号
"\t"+employees[i][1]+
"\t"+employees[i][2]+
"\t"+employees[i][3]+
"\t\n");

}
}

flag = false;
System.out.println("按0键返回主菜单-->");
break;
case 5:

System.out.println("删除员工");
flag = false;
break;

case 6:
//排序
//对有效员工的工资进行从大到小排序
for (int i = 0; i < empCount-1; i++) {
for (int j = 0; j < empCount-1-i; j++) {

int salary1 = Integer.parseInt(employees[j][2]);
int salary2 = Integer.parseInt(employees[j+1][2]);
if(salary1>salary2){
String[] temp = employees[j];
employees[j] = employees[j+1];
employees[j+1] = temp;
}


}

}
System.out.println("按工资排序为:");
System.out.println("\t\t编号\t姓名\t工资\t部门\t");
for (int i = 0; i < empCount; i++) {
// if(employees[i]==null)
// break;

System.out.println("\t\t"+employees[i][0]+//编号
"\t"+employees[i][1]+
"\t"+employees[i][2]+
"\t"+employees[i][3]+
"\t\n");

}
flag = true;
System.out.println("按0键返回主菜单-->");
break;
case 7:
System.out.println("谢谢使用!!");
flag = false;
break;

default:
System.out.println("你选择的不是1-5,请重新输入!");
flag = true;
break;
}
} catch (Exception e) {
System.out.println("您输入的不是数字,请重新输入!");
e.printStackTrace();//把异常信息打印出来
flag = true;
}

}

} --------------------编程问答-------------------- 不是个数组么,检索关键字删除呗,修改难度大一点,但是可以直接调用 删除+新建 实现 --------------------编程问答-------------------- 我要的是代码实现和修改!而且这就是一个整体! --------------------编程问答-------------------- 哼
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,