title: Using array to store and manipulate objects data with java
body: <p>Im currently learning java and im trying to create an Employee management program that stores employee records into an array and allow management to manipulate the array and print any employee reports. So I create a menu and ten employee objects which got stored in an array...now what I want to do is allow the user to input employee details through the menu and that information will be stored inside the objects and I want the user to be able to search for an employee by their title and also display only male of female employees.</p>
  <p>I first started with my employee class where has my modifers</p>
  <pre><code>public class Employee{
    int emp_id=0;
    String fname=&quot;pebbles&quot;;
    String lname=null;
    String dob=null;
    String gender=null;
    String address=null;
    String title=null;
    String dateHired=null;
    String department=null;
    int hoursWorked=0;
    double rateOfpay=0.0;
    int leaveDays=0;
    double carAllowance=0.0;
    double monthlyGratuity=0.0;
    double taxRate=0.0; 
    
    public Employee(){}
    
    public Employee(int emp_id,String fname,String lname,String dob,String gender,String address,String title,String dateHired,String
    department,int hoursWorked,double rateOfpay,int leaveDays,double carAllowance,double monthlyGratuity,double taxRate){
       this.emp_id=emp_id;
       this.fname=fname;
       this.lname=lname;
       this.dob=dob;
       this.gender=gender;
       this.address=address;
       this.title=title;
       this.dateHired=dateHired;
       this.department=department;
       this.hoursWorked=hoursWorked;
       this.rateOfpay=rateOfpay;
       this.leaveDays=leaveDays;
       this.carAllowance=carAllowance;
       this.monthlyGratuity=monthlyGratuity;
       this.taxRate=taxRate;
    }
    
    public Employee(int emp_id,String fname,String lname){
       this.emp_id=emp_id;
       this.fname=fname;
       this.lname=lname;
    }
    
    public void setEmployeeId(int emp_id){
       this.emp_id=emp_id;
    }
  
    public void setFirstName(String fname){
       this.fname=fname;
    }
    
    public void setLastName(String lname){
       this.lname=lname;
    }
    
    public void setDateOfBirth(String dob){
       this.dob=dob;
    }   
    
    public void setGender(String gender){
       this.gender=gender;
    }
    
    public void setAddress(String address){
       this.address=address;
    }
    
    public void setTitle(String title){
       this.title=title;
    }
    
    public void setDateHired(String dateHired){
       this.dateHired=dateHired;
    }
    
    public void setDepartment(String department){
       this.department=department;
    }
    
    public void setHoursWorked(int hoursWorked){
       this.hoursWorked=hoursWorked;
    }
    
    public void setRateOfPay(double rateOfpay){
       this.rateOfpay=rateOfpay;
    }
    
    public void setLeaveDays(int leaveDays){
       this.leaveDays=leaveDays;
    }
    
    public void setCarAllowance(double carAllowance){
       this.carAllowance=carAllowance;
    }
    
    public void setMonthlyGratuity(double monthlyGratuity){
       this.monthlyGratuity=monthlyGratuity;
    }
    
    public void setTaxRate(double taxRate){
       this.taxRate=taxRate;
    }
    
    public int getEmployeeId(){
       return emp_id;
    }
    
    public String getFirstName(){
       return fname;
    }
    
    public String getLastName(){
       return lname;
    }
    
    public String getDateOfBirth(){
       return dob;
    }
    
    public String getGender(){
       return gender;
    }
    
    public String getAddress(){
       return address;
    }
    
    public String getTitle(){
       return title;
    }
    
    public String getDateHired(){
       return dateHired;
    }
    
    public String getDepartment(){
       return department;
    }
    
    public int getHoursWorked(){
       return hoursWorked;
    }
    
    public double getRateOfPay(){
       return rateOfpay;
    }
    
    public int getLeaveDays(){
       return leaveDays;
    }
    
    public double getCarAllowance(){
       return carAllowance;
    }
    
    public double getMonthlyGratuity(){
       return monthlyGratuity;
    }
    
    public double getTaxRate(){
       return taxRate;
    }
  
  
  }
  </code></pre>
  <p>Then created  the objects and arrays in the class below</p>
  <pre><code>import java.util.Scanner;
  public class employeeArray extends Employee{
  
    private static Employee employees[] = new Employee[10];
    
  
       
    static Scanner input=null;
    String fname=&quot;pebbles&quot;;
    String lname=null;
    String dob=null;
    String gender=null;
    int emp_id=0;
    String address=null;
    String title=null;
    String dateHired=null;
    String department=null;
    int hoursWorked=0;
    double rateOfpay=0.0;
    int leaveDays=0;
    double carAllowance=0.0;
    double monthlyGratuity=0.0;
    double taxRate=0.0;
    
    
    public static Employee e1=new Employee(12345,&quot;Aobakwe&quot;,&quot;Mothabi&quot;,&quot;26/07/1990&quot;,&quot;Male&quot;,&quot;Private 009 Masunga&quot;,&quot;CEO&quot;,
          &quot;06/02/2008&quot;,&quot;Finance&quot;,500,50.0,10,100.0,1500,5.1);
          
    public static Employee e2=new Employee();
    
    public static Employee e3=new Employee();
    
    public static Employee e4=new Employee();
    
    public static Employee e5=new Employee();
    
    public static Employee e6=new Employee();
    
    public static Employee e7=new Employee();
    
    public static Employee e8=new Employee();
    
    public static Employee e9=new Employee();
    
    public static Employee e10=new Employee();
    
  
  
  
  
    
    public static void main(String args[]){
       input=new Scanner(System.in);
    
       Employee e1=new Employee(12345,&quot; &quot;,&quot;Mothabi&quot;,&quot;26/07/1990&quot;,&quot;Male&quot;,&quot;Private 009 Masunga&quot;,&quot;CEO&quot;,
          &quot;06/02/2008&quot;,&quot;Finance&quot;,500,50.0,10,100.0,1500,5.1);
          
       Employee e2=new Employee();
    
       Employee e3=new Employee();
    
       Employee e4=new Employee();
    
       Employee e5=new Employee();
    
       Employee e6=new Employee();
    
       Employee e7=new Employee();
    
       Employee e8=new Employee();
    
       Employee e9=new Employee();
    
       Employee e10=new Employee();
    
          
      
       
       employees[0]=e1;
       employees[1]=e2;
       employees[2]=e3;
       employees[3]=e4;
       employees[4]=e5;
       employees[5]=e6;
       employees[6]=e7;
       employees[7]=e8;
       employees[8]=e9;
       employees[9]=e10;
       
  
  
     //ENTER NAME
       System.out.println(&quot;Enter name&quot;);
       String fname=input.next();
       e2.setFirstName(fname);
       
       //ENTER LAST NAME
       System.out.println(&quot;Enter surname&quot;);
       String lname=input.next();
       e2.setLastName(lname);
       
       //ENTER DATE OF BIRTH
       System.out.println(&quot;Enter date of birth&quot;);
       String dob=input.next();
       e2.setDateOfBirth(dob);
       
       //ENTER GENDER
       System.out.println(&quot;Enter Gender&quot;);
       String gender=input.next();
       e2.setGender(gender);
       
       //ENTER EMPLOYEE ID
       System.out.println(&quot;Enter Employee Id&quot;);
       int emp_id=input.nextInt();
       e2.setEmployeeId(emp_id);
       
        //ENTER ADDRESS
       System.out.println(&quot;Enter Address&quot;);
       String address=input.next();
       e2.setAddress(address);
       
        //ENTER TITLE
       System.out.println(&quot;Enter Employee Title&quot;);
       String title=input.next();
       e2.setTitle(title);
       
       //ENTER DATE HIRED
       System.out.println(&quot;Enter Date Hired&quot;);
       String dateHired=input.next();
       e2.setDateHired(dateHired);
       
        //ENTER DEPARTMENT
       System.out.println(&quot;Enter Department&quot;);
       String department=input.next();
       e2.setDepartment(department);
       
       //ENTER HOURS WORKED
       System.out.println(&quot;Enter Hours Worked&quot;);
       int hoursWorked=input.nextInt();
       e2.setHoursWorked(hoursWorked);
       
        //ENTER RATE OF PAY
       System.out.println(&quot;Enter Rate Of Pay&quot;);
       double rateOfpay=input.nextDouble();
       e2.setRateOfPay(rateOfpay);
       
       //ENTER LEAVE DAYS
       System.out.println(&quot;Enter Leave Days&quot;);
       int leaveDays=input.nextInt();
       e2.setLeaveDays(leaveDays);
       
        //ENTER CAR ALLOWANCE
       System.out.println(&quot;Enter Car Allowance&quot;);
       double carAllowance=input.nextDouble();
       e2.setCarAllowance(carAllowance);
       
        //ENTER MONTHLY GRATUITY
       System.out.println(&quot;Enter Monthly Gratuity&quot;);
       double monthlyGratuity=input.nextDouble();
       e2.setMonthlyGratuity(monthlyGratuity);
       
         //ENTER TAX RATE
       System.out.println(&quot;Enter Tax Rate&quot;);
       double taxRate=input.nextDouble();
       e2.setTaxRate(taxRate);
       
       
       //DISPLAY RESULTS
       System.out.println(e2.getFirstName());
       System.out.println(e2.getLastName());
       System.out.println(e2.getDateOfBirth());
       System.out.println(e2.getGender());
       System.out.println(e2.getEmployeeId());
       System.out.println(e2.getAddress());
       System.out.println(e2.getTitle());
       System.out.println(e2.getDateHired());
       System.out.println(e2.getDepartment());
       System.out.println(e2.getHoursWorked());
       System.out.println(e2.getRateOfPay());
       System.out.println(e2.getLeaveDays());
       System.out.println(e2.getCarAllowance());
       System.out.println(e2.getMonthlyGratuity());
       System.out.println(e2.getTaxRate());*/
                    
    }
  
  
    static void mainMenu(){
    
       System.out.println(
          &quot;Select an option\n&quot;+
          &quot;1)Add Employee Records\n&quot;+
          &quot;2) display only male of female employees\n&quot;+
          &quot;3) display all employees and their gross salaries\n&quot;+
          &quot;4) search for an employee and display salary calculated.\n&quot;);
    }
  
    }
    
  
  </code></pre>
  <p>and lastly here is my tester class which displays the menu and allows the user to select an option</p>
  <pre><code>import java.util.Scanner;
  
  public class empTester extends employeeArray{
  
     static Scanner input=null;
  
     public static void main(String args[]){
     
        input=new Scanner(System.in);
        mainMenu();
        
        int choice=input.nextInt();
        if(choice==1){
           menuAdd();
           int option=input.nextInt();
           if(option==1){EmployeeCreation();}
           else if(option==2){System.out.println(&quot;It works number 2&quot;);}
           else if(option==3){mainMenu();}
        }
        
        else if(choice==2){
           menuDisplay();
           int option=input.nextInt();
           if(option==1){System.out.println(&quot;It works number 1&quot;);}
           else if(option==2){System.out.println(&quot;It works number 2&quot;);}
           else if(option==3){System.out.println(&quot;It works number 3&quot;);}
           else if(option==4){System.out.println(&quot;It works number 4&quot;);}
           else if(option==5){mainMenu();}
        }
        
        else if(choice==3){
           menuSearch();
           int option=input.nextInt();
           if(option==1){System.out.println(&quot;It works number 1&quot;);}
           else if(option==2){System.out.println(&quot;It works number 2&quot;);}
           else if(option==3){mainMenu();}
        }
        
        else if(choice==4){
           System.out.println(&quot;This is the About Section&quot;);
        }
        
        else if(choice==5){
           System.out.println(&quot;Ending Program&quot;);
           System.exit(0);
        }
     
     }
  
  }
  
  </code></pre>
  <p>Yeah so I managed to find a way to enable the user to add an employee record and display details added. Im having trouble creating methods for other functions stated in the menu without having to create new objects.</p>