Beruflich Dokumente
Kultur Dokumente
import java.util.ArrayList;
import java.util.Scanner;
public class EmployeeManagement {
public static void main(String args[])
{
ArrayList<String> empNameList=new ArrayList<String>();
system?");
}
public void addEmpName(int numEmp,ArrayList<String> empList)
{
Scanner sc=new Scanner(System.in);
for(int i=1;i<=numEmp;i++)
{
System.out.println("ENter nameof the employee");
String name=sc.nextLine();
empList.add(name);
}
}
---------------------------------package comc2;
import java.util.Date;
public class
{
private
private
private
private
private
Employee
String designation;
Date dob;
int employeeID;
String name;
float salary;
}
public Date getDob()
{
return dob;
}
public int getEmployeeID()
{
return employeeID;
}
public String getName()
{
return name;
}
public float getSalary()
{
return salary;
}
public void setDesignation(String designation)
{
this.designation=designation;
}
public void setDob(Date dob)
{
this.dob=dob;
}
public void setEmployeeID(int employeeID)
{
this.employeeID=employeeID;
}
public void setName(String name)
{
this.name=name;
}
public void setSalary(float salary)
{
this.salary=salary;
}
}
package comc2;
import
import
import
import
import
import
java.text.ParseException;
java.text.SimpleDateFormat;
java.util.ArrayList;
java.util.Date;
java.util.Iterator;
java.util.Scanner;
empList.add(e);
}
public void displayEmployees(ArrayList<Employee> empList)
{
Iterator<Employee> itr = empList.iterator();
while(itr.hasNext())
{
Employee e = itr.next();
System.out.print("\n"+e.getName());
}
/*for(Employee e:empList)
{
System.out.print(e.getName());
}*/
/*for(int i=0;i<empList.size();i++)
{
System.out.print("\n"+empList.get(i).getName()
+""+empList.get(i).getDesignation());
//System.out.print(e);
}*/
/*Employee e =new Employee();
for(int i=0;i<empList.size();i++)
{
e1=empList.get(i); //same as above..varies just in
assinging e1
System.out.print(e1.getName()+""+e1.getDesignation()
+""+e1.getEmployeeID()+""+e1.getSalary()+""+e1.getDob());
}*/
}
}
-----------------package comc2;
import java.util.*;
import java.text.*;
public class ScanDate
{
public static void main(String[] args)
{
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
Scanner sc = new Scanner(System.in);
System.out.println("Eample: 12-25-2103");
System.out.print("Enter date: ");
String str = sc.nextLine();
try
{
java.text.ParseException;
java.text.SimpleDateFormat;
java.util.ArrayList;
java.util.Date;
java.util.Iterator;
java.util.Scanner;
loop
}
else
{
}
}*/
e.setName(name);
System.out.println("Enter designation:");
String designation = sc.nextLine();
e.setDesignation(designation);
Scanner sc1=new Scanner(System.in);
System.out.println("Enter id of the employee");
int employeeID=sc1.nextInt();
e.setEmployeeID(employeeID);
System.out.println("Enter salary of the employee");
float salary=sc1.nextFloat();
e.setSalary(salary);
System.out.println("Enter dob of the employee");
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
Scanner sc2 = new Scanner(System.in);
System.out.println("Eample: 12-25-2103");
System.out.print("Enter date: ");
String str = sc2.nextLine();
try
{
e.setDob(sdf.parse(str));
} catch (ParseException exp)
{
System.out.println("Parse Exception");
}
empList.add(e);
}
public void displayEmployees(ArrayList<Employee> empList)
{
Iterator<Employee> itr = empList.iterator();
while(itr.hasNext())
{
Employee e = itr.next();
System.out.print("\n"+e.getName());
/*for(Employee e:empList)
{
System.out.print(e.getName());
}*/
}
public boolean deleteEmployee(String eName,ArrayList<Employee>
empList)
{
boolean b=false; //to print one statement in a loop(flag)
Employee e1 =new Employee();
for(int i=0;i<empList.size();i++)
{
e1=empList.get(i);
if(eName.equals(e1.getName()))
{
empList.remove(e1);
System.out.print("\n"+eName+" is deleted from the
list");
b=true;
break;
/*for(Employee e:empList)
{
System.out.print("\n new list after
deletion is:"+e.getName());
}*/
}
else
{
list");
}
b=false;
//System.out.print("\n"+eName+" not there in
}
if(b==true)
{
System.out.print("\n element deleted");
}
else
{
System.out.print("\n required element not present to
be deleted");
}
return true;
}
public boolean isEmployeePresent(String eName,ArrayList<Employee>
empList)
{
boolean b=false;
Employee e1 =new Employee();
for(int i=0;i<empList.size();i++)
{
e1=empList.get(i);
//if(eName.equalsIgnoreCase(e1.getName()))
if(e1.getName().contains(eName))
{
System.out.print("\n"+e1.getName()+" is present
in the list");
b=true;
break;
}
else
{
b=false;
}
}
if(b==true)
{
System.out.print("\n IsEmployeePresent: present");
}
else
{
System.out.print("\n IsEmployeePresent: not present");
}
return b;
}
}
------------------package comset;
import java.util.Date;
public class
{
private
private
private
private
private
Employee
String designation;
Date dob;
int employeeID;
String name;
float salary;
import
import
import
import
import
import
java.text.ParseException;
java.text.SimpleDateFormat;
java.util.HashSet;
java.util.Iterator;
java.util.Scanner;
java.util.Set;
}*/
/* while(!empList.add(e))
{
System.out.println("id is duplicate value");
break;
}*/
System.out.println("Enter name of the employee");
String name = sc.nextLine();
e.setName(name);
//System.out.println(empList.add(e));
if(empList.add(e)==false)
{
}
System.out.println("Enter designation:");
String designation = sc.nextLine();
e.setDesignation(designation);
System.out.println("Enter salary of the employee");
float salary=sc1.nextFloat();
e.setSalary(salary);
System.out.println("Enter dob of the employee");
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
Scanner sc2 = new Scanner(System.in);
System.out.println("Eample: 12-25-2103");
System.out.print("Enter date: ");
String str = sc2.nextLine();
try
{
e.setDob(sdf.parse(str));
} catch (ParseException exp)
{
System.out.println("Parse Exception");
}
empList.add(e);
//System.out.println(empList.add(e));
}
}
public void displayEmployees(Set<Employee> empList)
{
while(itr.hasNext())
{
Employee e = itr.next();
System.out.print("\n"+e.getName());
/*for(Employee e:empList)
{
System.out.print(e.getName());
}*/
}
public boolean deleteEmployee(String eName,Set<Employee> empList)
{
boolean b=false; //to print one statement in a loop(flag)
//Employee e1 =new Employee();
//for(int i=0;i<empList.size();i++)
//{
Iterator<Employee> itr = empList.iterator();
while(itr.hasNext())
{
Employee e = itr.next();
//System.out.print("\n"+e.getName());
//e1=empList.get(i);
if(eName.equals(e.getName()))
{
empList.remove(e);
System.out.print("\n"+eName+" is deleted from the
list");
b=true;
break;
/*for(Employee e:empList)
{
System.out.print("\n new list after
deletion is:"+e.getName());
}
else
{
}*/
b=false;
//System.out.print("\n"+eName+" not there in
list");
}
}
//}
if(b==true)
{
System.out.print("\n element deleted");
}
else
{
System.out.print("\n required element not present to
be deleted");
}
return true;
}
public boolean isEmployeePresent(String eName,Set<Employee>
empList)
{
boolean b=false; //to print one statement in a loop(flag)
Iterator<Employee> itr = empList.iterator();
while(itr.hasNext())
{
Employee e = itr.next();
the list");
//if(e.getName().contains(eName))
if(eName.equals(e.getName()))
{
System.out.print("\n"+e.getName()+" is present in
b=true;
break;
}
else
{
present");
if(b==true)
{
System.out.print("\n IsEmployeePresent:
}
else
{
present");
}
b=false;
}
return true;
}
----------------------package comMap;
import java.util.Date;
public class
{
private
private
private
private
private
Employee
String designation;
Date dob;
int employeeID;
String name;
float salary;
this.employeeID=employeeID;
java.text.ParseException;
java.text.SimpleDateFormat;
java.util.ArrayList;
java.util.ConcurrentModificationException;
java.util.HashMap;
java.util.Iterator;
java.util.Map;
java.util.Map.Entry;
java.util.Scanner;
java.util.Set;
System.out.println("Enter designation:");
String designation = sc.nextLine();
e.setDesignation(designation);
System.out.println("Enter salary of the employee");
float salary=sc1.nextFloat();
e.setSalary(salary);
System.out.println("Enter dob of the employee");
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
Scanner sc2 = new Scanner(System.in);
System.out.println("Eample: 12-25-2103");
System.out.print("Enter date: ");
String str = sc2.nextLine();
try
{
e.setDob(sdf.parse(str));
} catch (ParseException exp)
{
System.out.println("Parse Exception");
}
System.out.println("Enter Hobby-name:");
String hn = sc.next();
h.setHobbyName(hn);
System.out.println("Enter Hobby-description");
String hd = sc.next();
h.setHobbyDescription(hd);
empList.put(e,h);
}
}
return true;
if(m.getValue() == k)
System.out.println(m.getKey().getName() + " " +
m.getValue().getHobbyName());
}
b=true;
break;
}
else
}
b=false;
if (b == true)
System.out.println("The employee is present");
else
System.out.println("The employee is not present");
}
}
return b;