当前位置: 代码迷 >> Java相关 >> [求助]我们考试的题,怎么做?
  详细解决方案

[求助]我们考试的题,怎么做?

热度:424   发布时间:2006-02-28 13:31:00.0
[求助]我们考试的题,怎么做?
运用一维数组设计一个员工工资管理系统,有查询修改功能.(console下的程序)
数组是提供好了的,里面存的是员工的工资.
int gz[]=new gz[5];
gz[0]=1100;gz[1]=1400;gz[2]=1800;gz[3]=1100;gz[4]=2000;
提示:
利用个while生成一个用户菜单供用户选择,第1项为查询员工数据,第2项为修改员工工资,第3项为结束系统.
当用户选择1或2时,先要求用户输入员工编号就是数组下标,程序再判断是否正确的员工编号,若正确,
刚显示员工工资,若错误,提示,"the error employee number!"
若用户选2项时,再进一步要求用户输入修改后的员工工资,并将数据存回员工工资数组中.
搜索更多相关的解决方案: 考试  

----------------解决方案--------------------------------------------------------

import java.io.*;
public class Wage {
private int gz[]=new int[5];
public Wage(){
gz[0]=1100;
gz[1]=1400;
gz[2]=1800;
gz[3]=1100;
gz[4]=2000;
}
private int doSelect(){
int i=-1;
String s=new String();
try{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
s=br.readLine();
}
catch(IOException ioe){
ioe.printStackTrace();
System.out.println("There are some error while input!");
}
try{
i=Integer.parseInt(s);
}
catch(NumberFormatException nfe){
nfe.printStackTrace();
System.out.println("The format Error!");
}
return i;

}
private void doList(){
int i=doSelect();
if(i>=0&&i<=4)
System.out.println("The wage of "+i+"'s is: "+gz[i]);
else
System.err.println("Error input!");

}
private void doUpdate(){
int i=doSelect();
if(i>=0&&i<=4){
System.out.print("Please input a new wage: ");
int j=doSelect();
gz[i]=j;
System.out.println("Update success!");
}
else
System.err.println("Error input!");

}
public static void main(String args[]){
Wage w=new Wage();
while(true){
System.out.println("----------------------------------------");
System.out.println("Please input your choice(1--3):");
System.out.println("1.List one employee's wage.");
System.out.println("2.Update one employee's wage.");
System.out.println("3.Exit the system!");
int i=w.doSelect();
switch(i){
case 1:
System.out.println("Please input your choice:(0--4)");
w.doList();
break;
case 2:
System.out.println("Please input your choice:(0--4)");
w.doUpdate();
break;
case 3:
System.out.println("Bye-bye!");
System.exit(0);
default:
System.out.println("Error Input!");
}
}
}

}


----------------解决方案--------------------------------------------------------
  相关解决方案