Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
//Employee class.............

package employeedetails;
public class EmployeeDetails {

    private String EmpName;
    private int EmpId;

    public String getEmpName(){
        return EmpName;
    }

     public int getEmpId(){
        return EmpId;
    }
    EmployeeDetails(String EmpName,int EmpId){
        this.EmpName=EmpName;
        this.EmpId=EmpId;
    }

   public String toString(){
       return "EMployeeName= "+EmpName+" EmployeeID= "+EmpId;
    }
    
}


/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Java
// Main class

package employeedetails;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Scanner;
public class Employee {
       String name;
       int id;
       Scanner s= new Scanner(System.in);
       EmployeeDetails employeeDetails=null;
       Hashtable<string,employeedetails> h= new Hashtable<string,employeedetails> ();

        public static void main(String[] args) {

        Employee employee= new Employee();
        employee.callMe();
    }
       public void callMe(){
           System.out.println("you want to add emp details");
          char ch= Employee.getChar();
           if(ch=='y'||ch=='Y'){
            getData();
      employeeDetails= new EmployeeDetails(name,id);
      h.put(name, employeeDetails);
           for(Enumeration<employeedetails> en = h.elements();en.hasMoreElements();) {
              employeeDetails = en.nextElement();
              System.out.println(employeeDetails); }
        }
    else{}
    }

     public void getData(){
      System.out.println("Enter Emp name");
      name= InputValidation.getString();
      System.out.println("Enter Emp id");
      id= Integer.parseInt(InputValidation.getInteger());
      callMe();
    }
     public static char getChar(){
				Scanner scn= new Scanner(System.in);
				char ch=scn.next().toLowerCase().charAt(0);
				if(!(ch=='y'||ch=='Y'||ch=='n'||ch=='N')){
				System.out.println("Enter only YES/NO");
                               ch= getChar(); }
			return ch;
				}

}



o/p:
you want to add emp details
y
Enter Emp name
bee
Enter Emp id
123
you want to add emp details
y
Enter Emp name
kira
Enter Emp id
23456
you want to add emp details
y
Enter Emp name
been
Enter Emp id
899
you want to add emp details
n
EMployeeName= been EmployeeID= 899
EMployeeName= been EmployeeID= 899
EMployeeName= been EmployeeID= 899
Posted
Updated 6-Feb-15 22:46pm
v2

1 solution

You have a bad recursive loop in your code. Method main calls callMe, which then calls getData. However, when getData has collected its input data, it, in turn, calls callMe, which then calls getData, and so on.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900