Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all change the class name to <code>Employee</code> instead of <code>employee</code>. Stick with java naming conventions. Now You should take advantage of java utility classes instead . for Example <code>ArrayList&lt;Employee&gt;</code>. <code>ArrayList</code> implements dynamically resizing array, which lets the user to insert as much amount of data within it without worrying about the current size of the internal <code>array</code> because <code>ArrayList</code> is there to take care of it. But before using <code>ArrayList</code> to store your <code>Employee</code> objects you need to override <code>equals</code> method in <code>Employee</code> because <code>ArrayList</code> internally uses this method to find out the existence of look a like object in some methods. The <code>equals</code> method looks as follows within <code>Employee</code> class:</p> <pre><code>@Override public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof Employee) { Employee anotherEmployee = (Employee)anObject; if ((this.toString()).equals(anotherEmployee.toString())) { return true; } return false; } return false; } @Override public String toString()//Override it so that it could be easier to compare two objects of Employee using toString() { return empID+","+empName+","+job; } </code></pre> <p>Now , You can use <code>ArrayList</code> in following way:</p> <pre><code>List&lt;Employee&gt; list = new ArrayList&lt;Employee&gt;(); for(size = 0; size &lt; 2; size++) { p("Employee "+(size+1)); p("Please enter employee ID number: "); empID = k.nextInt(); k.nextLine(); p("Please enter your name: "); empName = k.nextLine(); p("Please enter your job role: "); job = k.nextLine(); Employee employee = new Employee(); employee.setEmpID(empID); employee.setEmpName(empName); employee.setJob(job); list.add(employee); } for(int i = 0 ;i &lt; list.size() ; i++){ Employee employee = list.get(i); p("Hello employee: "+employee.getEmpName()+" your job role is "+employee.getJob()+ " your log in ID is 0800"+employee.getEmpID()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload