⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employeedb.java

📁 一個自己寫的簡單員工管理系統
💻 JAVA
字号:
// create data class Employee
// create implementation class using dos version

import java.io.*;
import java.lang.*;


class Employee{
	private int id;
	private String name;
	private String icno;
	private char gender;
	private String dob;
	private String addr;
	private String comdate;
	private String dept;
	private String post;
	private double salary;

	
	// constructors
	public Employee (int a, String b, String c, char d, String e, String f, String g, String h, String i, double j){
		
		id = a;
		name = b;
		icno =  c;
		gender = d;
		dob = e;
		addr = f;
		comdate = g;
		dept = h;
		post = i;
		salary = j;
	}	 

	// overloading constructor
	public Employee (int a){
		
		id = a ;
	}
	
	// setter methods
	public void setID (int a){
		id = a;
	}

	public void setName (String b){
		name = b;
	}

	public void setIcno (String c){
		icno = c;
	}

	public void setGender (char d){
		gender = d;
	}

	public void setDob (String e){
		dob = e;
	}

	public void setAddr (String f){
		addr = f;
	}

	public void setComdate (String g){
		comdate = g;
	}

	public void setDept (String h){
		dept = h;
	}

	public void setPost (String i){
		post = i;
	}

	public void setSalary (double j){
		salary = j;
	}

	// getter methods
	public int getID(){
		return id;
	}

	public String getName(){
		return name;
	}

	public String getIcno(){
		return icno;
	}

	public char getGender(){
		return gender;
	}

	public String getDob(){
		return dob;
	}

	public String getAddr(){
		return addr;
	}

	public String getComdate(){
		return comdate;
	}

	public String getDept(){
		return dept;
	}

	public String getPost(){
		return post;
	}

	public double getSalary(){
		return salary;
	}
		
}

/* implementation class */
public class EmployeeDb{
	static Employee emp[]=new Employee[3];
                    static int recNo;
                    static int indexNo;

	public static void main(String [] args) throws Exception{
		EmployeeDb db =new EmployeeDb();
		BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
		int opt;
           		recNo =10000;
		
		do{
			db.mainMenu();
			opt=Integer.parseInt(stdin.readLine());
			switch (opt){
			     case 1	: db.addEmployee(); break;
			     case 2	: db.srcEmployee(); break;
			     case 3	: db.dispEmployee(); break;
			}

		}while(opt  !=0);
		System.out.println("END OF SYSTEM");
		System.out.println("THANK YOU");
                  }
		


	public void mainMenu(){
		System.out.println("\n");
		System.out.println("Main Menu");
		System.out.println("=========");	
		System.out.println(" (1) Add Employee");
		System.out.println(" (2) Search Employee");
		System.out.println(" (3) Display Employee");
		System.out.println(" (0) Exit system");
		System.out.print("Please Enter selection   : ");
	}

	public void addEmployee() throws Exception{
		
		int  id;
		String name;
		String icno;
		char gender;
		String dob;
		String addr;
		String comdate;
		String dept;
		String post;
		double salary;

 		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

		System.out.println("\tAdd Employee");
		System.out.println("\t============");
		System.out.println("\n\n");
		recNo++;
		emp[indexNo] = new Employee(recNo);

		System.out.println("New Employee ID " +recNo );
		System.out.println("=================");
		System.out.print("Please Enter Name  "  );
		String b = stdin.readLine();
		System.out.println("=================");
		System.out.print("Please Enter IC No  "  );
		String c = stdin.readLine();
		System.out.println("=================");
		System.out.print("Please Enter m=Male/f=Female "  );
		String s = stdin.readLine();
    		char d = s.charAt(0);
			switch(d){
					case 'm':
					System.out.println("You enter Male");break;
					case 'f':
					System.out.println("You enter Female");break;
					default:
					System.out.println("Invalid data entry");break;
				}
		System.out.println("=================");
		System.out.print("Please Enter DOB  "  );
		String e = stdin.readLine();
		System.out.println("=================");
		System.out.print("Please Enter Address  "  );
		String f = stdin.readLine();
		System.out.println("=================");
		System.out.print("Please Enter Com Date  "  );
		String g = stdin.readLine();
		System.out.println("=================");
		System.out.print("Please Enter Department "  );
		String h = stdin.readLine();
		System.out.println("=================");
		System.out.print("Please Enter Position  "  );
		String i = stdin.readLine();
		System.out.println("=================");
		System.out.print("Please Enter Salary  "  );
		double j=Integer.parseInt(stdin.readLine());
		System.out.println("=================");
		

		emp[indexNo].setID(recNo);
		emp[indexNo].setName(b);
		emp[indexNo].setIcno(c);
		emp[indexNo].setGender(d);
		emp[indexNo].setDob(e);
		emp[indexNo].setAddr(f);
		emp[indexNo].setComdate(g);
		emp[indexNo].setDept(h);
		emp[indexNo].setPost(i);
		emp[indexNo].setSalary(j);
		indexNo++;

	}


	public void srcEmployee()  throws Exception{
		
		int id;
		String name;
		String icno;
		char gender;
		String dob;
		String addr;
		String comdate;
		String dept;
		String post;
		double salary;
		char pause;
		int i;
		int found = -1;
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

		System.out.println("\tSearch Employee");
		System.out.println("\t===============");
		System.out.print("Please Enter ID "  );
		id = Integer.parseInt(stdin.readLine());
		for(i =0; i < emp.length; i++){
			if (id == emp[i].getID())
				found = i;	
		}
		if (found < 0 )
			System.out.println("\n\n\t\t Record Not Found \n\n");
		else{
			System.out.println("Name	\t:"+emp[found].getName()  );
			System.out.println("IC No	\t:"+emp[found].getIcno()  );
			System.out.println("Gender	\t:"+emp[found].getGender() );
			System.out.println("DOB		:"+emp[found].getDob() );
			System.out.println("Address	\t:"+emp[found].getAddr() );
			System.out.println("Com Date	:"+emp[found].getComdate() );
			System.out.println("Department	:"+emp[found].getDept() );
			System.out.println("Position	:"+emp[found].getPost() );
			System.out.println("Salary	\t:"+emp[found].getSalary() );
		}
		
	}

	public void dispEmployee()  throws Exception{
		
		int  id;
		String name;
		String icno;
		char gender;
		String dob;
		String addr;
		String comdate;
		String dept;
		String post;
		double salary;
		int i;
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));


		System.out.println("\tDisplay Employee");
		System.out.println("\t================");
		for(i =0; i < emp.length; i++){
			System.out.println("Name	\t:"+emp[i].getName()  );
			System.out.println("IC No	\t:"+emp[i].getIcno()  );
			System.out.println("Gender	\t:"+emp[i].getGender() );
			System.out.println("DOB	\t:"+emp[i].getDob() );
			System.out.println("Address	\t:"+emp[i].getAddr() );
			System.out.println("Com Date	:"+emp[i].getComdate() );
			System.out.println("Department	:"+emp[i].getDept() );
			System.out.println("Position	:"+emp[i].getPost() );
			System.out.println("Salary	\t:"+emp[i].getSalary() );	
			System.out.println( );	
		}
	}	
}



	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -