职员薪水管理系统需求如下:
/**标签:java,String,薪水,ArrayList,System,empNo,employee,println,out From: https://blog.51cto.com/u_9427273/6008299
* author:kevin
* date:20110-7-15
* function:use ArrayList to build a system of EmployeeSalaryMangement ,
* the system is useful for manager to add new employee'information,delete employee'information,
* update employee'information,and show employee'information.
* it's easy to obtain the OOP.
* */
import java.util.ArrayList;
import java.io.*;public class EmployeeSalary {
public static void main(String[] args) throws Exception{
//create object EmpManage
EmpManage empm = new EmpManage();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
//create a menu
while(true)
{
System.out.println("select what you want to do");
System.out.println("select 1:insert new employee");
System.out.println("select 2:show information");
System.out.println("select 3:delete employee");
System.out.println("select 4:update salary");
System.out.println("select 5:excit");
String oper= br.readLine();
if (oper.equals("1")){
System.out.println("input number:");
String empNo = br.readLine();
System.out.println("input name:");
String empName = br.readLine();
System.out.println("input salary:");
float salary=Float.parseFloat(br.readLine());
Emp emp = new Emp(empNo,empName,salary);
empm.addEmp(emp);
}else if (oper.equals("2")){
System.out.println("input number:");
String empNo = br.readLine();
empm.showEmp(empNo);
}else if (oper.equals("3")){
System.out.println("input number:");
String empNo = br.readLine();
empm.delEmp(empNo);
}else if (oper.equals("4")){
System.out.println("input number:");
String empNo = br.readLine();
System.out.println("input new salary:");
float newSalary =Float.parseFloat(br.readLine()) ;
empm.updateEmp(empNo, newSalary);
}else if (oper.equals("5")){
//exit system.
System.exit(0);
}
} }
}
//*****************************************************************
//class Employee
class Emp
{
private String empNo; //employee number
private String empName; //employee name
private float salary; //employee salary
public String getEmpNo() {
return empNo;
}
public void setEmpNo(String empNo) {
this.empNo = empNo;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
} public Emp(String empNo,String empName,float salary)
{
this.empNo = empNo;
this.empName = empName;
this.salary = salary;
}}
//**********************************************************
//class EmployeeSalaryManage
class EmpManage
{
private ArrayList al = null;
public EmpManage()
{
al = new ArrayList();
}
//insert new employee
public void addEmp(Emp emp)
{
al.add(emp);
}
//show information
public void showEmp(String empNo)
{
for (int i= 0 ;i<al.size();i++)
{//get object
Emp emp = (Emp)al.get(i);
if(emp.getEmpNo().equals(empNo))
{
System.out.println("The employee is founded:");
System.out.println("The employee'number:"+emp.getEmpNo());
System.out.println("The employee'name:"+emp.getEmpName());
System.out.println("The employee'salary:"+emp.getSalary());
}
}
}
//delete employee
public void delEmp(String empNo)
{
for (int i= 0 ;i<al.size();i++)
{//get object
Emp emp = (Emp)al.get(i);
if(emp.getEmpNo().equals(empNo))
{
System.out.println("The employee which number is "+emp.getEmpNo()
+"is deleted successfully");
al.remove(i);
}
}
}
//update employee
public void updateEmp(String empNo,float newSalary)
{
for (int i= 0 ;i<al.size();i++)
{//get object
Emp emp = (Emp)al.get(i);
if(emp.getEmpNo().equals(empNo))
{
emp.setSalary(newSalary);
System.out.println("update successfully");
}
}
}}