This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
public void addEmployees(int numEmp,ArrayList<Employee> empList){
Scanner sc=new Scanner(System.in);
for(int i=1;i<=numEmp;i++){
Employee e =new Employee(); //should be kept inside loop
System.out.println("Enter name of the employee");String name = sc.nextLine();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 { //Date date = sdf.parse(str); e.setDob(sdf.parse(str)); //sdf = new SimpleDateFormat("EEE, d MMM yyyy"); //System.out.println("Date: " + sdf.format(date)); } catch (ParseException exp) { System.out.println("Parse Exception"); }
//System.out.println("Dob is:"+e.getDob());
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());
public void addEmployees(int numEmp,ArrayList<Employee> empList){
Scanner sc=new Scanner(System.in);
for(int i=1;i<=numEmp;i++){
Employee e =new Employee(); //should be kept inside loop
System.out.println("Enter name of the employee");String name = sc.nextLine();e.setName(name);/*Employee e1 =new Employee(); for(int j=0;j<empList.size();j++){e1=empList.get(i);if(e1.getName().equals(name)){
System.out.println("This name is already present");
}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)
public void addEmpName(int numEmp,Set<Employee> empList){
Scanner sc=new Scanner(System.in);
for(int i=1;i<=numEmp;i++){
Employee e =new Employee(); //should be kept inside loop
Scanner sc1=new Scanner(System.in);
System.out.println("Enter id of the employee"); int employeeID=sc1.nextInt(); e.setEmployeeID(employeeID); //System.out.println(empList.add(e)); /* if(empList.add(e)==false)
{ System.out.println("id is duplicate value"); continue; }*/ /* 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("name is duplicate value"); continue; }
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"); }
public void addEmpName(int numEmp,Map<Employee,Hobby> empList){
for(int i=1;i<=numEmp;i++){
Employee e =new Employee(); Hobby h=new Hobby();
Scanner sc1=new Scanner(System.in);System.out.println("Enter id of the employee");
int employeeID=sc1.nextInt(); e.setEmployeeID(employeeID); //System.out.println(empList.add(e)); /* if(empList.add(e)==false) { System.out.println("id is duplicate value"); continue; }*/
System.out.println("Enter name of the employee");Scanner sc=new Scanner(System.in);String name = sc.nextLine();e.setName(name);//System.out.println(empList.add(e));/*if(empList.add(e)==false)
{ System.out.println("name is duplicate value"); continue; }*/
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:");
public void displayEmployees(Map<Employee,Hobby> hm){
for (Map.Entry<Employee, Hobby> m : hm.entrySet()) { System.out.println(m.getKey() +" "+m.getKey().getName() +" " + m.getValue().getHobbyName()); }
}
public boolean deleteEmployee(int id,Map<Employee,Hobby> m1){try{for (Entry<Employee, Hobby> entry : m1.entrySet()){
Employee e = entry.getKey(); // here you have the employee // check if this employee have same id than given if(e.getEmployeeID() == id) { // map contains the employee //System.out.println (m1.remove(e)); m1.remove(e); System.out.println ("After deletion:------"); for (Map.Entry<Employee, Hobby> m : m1.entrySet()) { System.out.println(m.getKey() + " " + m.getValue().getHobbyName()); } } }