Employee management operations for ArrayList

Source: Internet
Author: User

Package com. EMP;

Import java.io.*;
Import java.util.*;


public class Manageemp {

/**
* @param args
*/
public static void Main (string[] args) throws Exception {
TODO auto-generated Method Stub
Empmanage em=new empmanage ();
BufferedReader br=new BufferedReader (New InputStreamReader (system.in));
while (true)
{
SYSTEM.OUT.PRINTLN ("Employee Management" (1: Add an employee.) 2: Find an employee. 3: Change the salary of an employee. 4: Delete an employee. 5: Launch System ");
String Opertype=br.readline ();
if (Opertype.equals ("1"))
{
System.out.println ("Please enter Number:");
String Empno=br.readline ();
System.out.println ("Please enter Name:");
String Name=br.readline ();
System.out.println ("Please enter Salary:");
Float Sal=float.parsefloat (Br.readline ());
EMP emp=new EMP (empNo, name, Sal);
Em.addemp (EMP);
}
else if (Opertype.equals ("2"))
{
System.out.println ("Please enter Number:");
String Empno=br.readline ();
Em.showinfo (EmpNo);
}
else if (Opertype.equals ("3"))
{
System.out.println ("Please enter Number:");
String Empno=br.readline ();
System.out.println ("Please enter change work:");
Float Newsal=float.parsefloat (Br.readline ());
Em.updatesal (EmpNo, newsal);
}
else if (Opertype.equals ("4"))
{
System.out.println ("Please enter Number:");
String Empno=br.readline ();
Em.delemp (EmpNo);
}
else if (Opertype.equals ("5"))
{
System.exit (-1);
}
}
}
}

Class empmanage{
Private ArrayList Al=null;
Public Empmanage () {
Al=new ArrayList ();
}
public void Addemp (EMP emp) {
Al.add (EMP);
}
public void Showinfo (String empNo) {

Traverse Arraylsit
for (int i=0;i<al.size (); i++) {
EMP emp= (EMP) al.get (i);
if (Emp.getempno (). Equals (EmpNo))
{
SYSTEM.OUT.PRINTLN ("Employee information is:");
System.out.println ("Number:" +empno);
SYSTEM.OUT.PRINTLN ("Employee information is:" +emp.getname ());
SYSTEM.OUT.PRINTLN ("Employee salary is:" +emp.getsal ());

}

}
}
public void Updatesal (String empno,float newsal) {
for (int i=0;i<al.size (); i++)
{
EMP emp= (EMP) al.get (i);
if (Emp.getempno (). Equals (EmpNo))
{
Emp.setsal (newsal);
}
}
}
public void Delemp (String empNo)
{
for (int i=0;i<al.size (); i++)
{
EMP emp= (EMP) al.get (i);
if (Emp.getempno (). Equals (EmpNo))
{
Al.remove (i);
Al.remove (EMP);
}
}
}
}

Class emp{
Private String EmpNo;
private String name;
private float Sal;
Public Emp (String empno,string name,float sal) {
This.empno=empno;
This.name=name;
This.sal=sal;
}
Public String Getempno () {
return empNo;
}
public void Setempno (String empNo) {
This.empno = EmpNo;
}
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
public float getsal () {
return Sal;
}
public void Setsal (float sal) {
This.sal = sal;
}

}

Employee management operations for ArrayList

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.