Application of Java core technology in arraylist [Employee Salary Management System]

Source: Internet
Author: User

The requirements of the employee salary management system are as follows:

/**
* 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 rows = Br. Readline ();
If (response. 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 = new EMP (empno, empname, salary );

Empm. addemp (EMP );

} Else if (response. Equals ("2 ")){
System. Out. println ("input number :");

String empno = Br. Readline ();

Empm. showemp (empno );
} Else if (response. Equals ("3 ")){
System. Out. println ("input number :");

String empno = Br. Readline ();

Empm. delemp (empno );
} Else if (response. 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 (response. 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)
{
Al. Add (EMP );
}
// Show information
Public void showemp (string empno)
{
For (INT I = 0; I <Al. Size (); I ++)
{

// Get object
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) 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) Al. Get (I );
If (EMP. getempno (). Equals (empno ))
{
EMP. setsalary (newsalary );
System. Out. println ("Update successfully ");
}
}
}

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.