I've been writing a java application to run employee data and compute their salary. I'm having some problem with my Manager class. Manager class is for adding and removing employee record supervise by a manager and compute their total salary. Can anyone guide me how to develope this class with array. I had written the code of this class just don't know how to use array to make it work. Can anyone give some advice and guideto develop this class with arrayand what's wrong with my code? Here's my codefor the application:-

import java.io.*;
// driver class
public class EmpMonthPayment {

    public static void main(String[] args) throws IOException {

//       create keyboard stream and data variables
          BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
          EmployeeData[] data = new EmployeeData[3];
          for (int i = 0; i < data.length; i++)
          {
          // declare variables
          String jobStatus; 
          String id; 
          String name;
          String hireDate;
          String jobStat;
          String addEmployee = "";
          String delEmployee = "";
          double weeklySalary;
          double groupSalary = 0.0;
          int totalHours;
          int totalOT;

        // create instance for Employee Details
          System.out.print("Enter employee Job Status Full Time or Part Time: ");
          jobStat = stdin.readLine();
          System.out.print("Enter employee ID: ");
          id = stdin.readLine();
          System.out.print("Enter employee Name: ");
          name = stdin.readLine();
          System.out.print("Enter employee Hire date: ");
          hireDate = stdin.readLine();
          System.out.print("Enter a employee Weekly Salary: ");
          weeklySalary = Double.valueOf(stdin.readLine()).doubleValue();
          System.out.print("Enter Part Time employee Total Working Hours in a month: ");
          totalHours = Integer.parseInt(stdin.readLine());
          System.out.print("Enter Part Time employee Total OverTime Hours in a month: ");
          totalOT = Integer.parseInt(stdin.readLine());



          //  create a EmployeeData object

          data[i] = new EmployeeData(id, name, hireDate, weeklySalary);
          data[i] = new Manager(id, name, hireDate, weeklySalary, groupSalary, addEmployee, delEmployee);

          if(jobStat.equals("Full Time"))
          {
          data[i] = new FullTimeEmployee(id, name, hireDate, weeklySalary);
          }
          else
          {
          data[i] = new PartTimeEmployee(id, name, hireDate, weeklySalary, totalHours, totalOT);
          }
          }

          System.out.println("The Employees details are:");
          System.out.println();
          System.out.println("ID\t Name\t\tHireDate\tWeekly Salary");
          System.out.println("-------------------------------------------------------------------");

/// run through each element of the array
          for (int i = 0; i < data.length; i++)
          {
             displayData(data[i]);
          }
       }
// Display Data     
    public static void displayData(EmployeeData in)
       {    
        System.out.println(in.getId() +
                "\t" + in.getName() + 
                "\tN/A\t" + in.getHireDate() +
                "\t" + in.getPay()); 

        }


    }
//Employee class: stores data of an employee.
class EmployeeData
{
    private String name;
    private String id;
    private String hireDate;
    public double pay;

    //   constructor 
       EmployeeData()
       {
         id = " ";
         name = "Unknown Item";
         hireDate = " ";
         pay = 0.0;
       }

//     another constructors
       EmployeeData(String id, String name, String hireDate, double pay)
       {
          this.id = id;
          this.name = name;
          this.hireDate = hireDate;
          this.pay = pay;

       }

       // mutators for variables
       public void setId(String id)
       {
          this.id= id;
       }

       public void setName(String name)
       {
        this.name = name;
       }

       public void setHireDate(String hireDate)
       {
        this.hireDate = hireDate;
       }

       public void setPay(double pay)
       {
        this.pay = pay;
       }

       // accessors for variables
       public String getId()
       {
          return id;
       }

       public String getName()
       {
          return name;
       }

       public String getHireDate()
       {
          return hireDate;
       }

       public double getPay()
       {
          return pay;
       }

}

// Full Time Employee Class
class FullTimeEmployee extends EmployeeData
{
       //   salary constant
       public static final double SALARY = 4.3;

       // default constructor
       FullTimeEmployee()
       {
          super();

       }

    //   full constructor
       FullTimeEmployee(String id, String name, String hireDate, double pay)
       {
          super(id, name, hireDate, pay);
       }

       // overridden inc salary accessor
       public double getPay()
       {
          return super.getPay()* SALARY;
       }

}

// Part Time Employee Class
class PartTimeEmployee extends EmployeeData
{
    public static final double NORMAL_HOURLY_RATE = 25;
    public static final double OT_HOURLY_RATE = 50;

     // class variables
     public int totalHours;
     public int totalOT;

       // default constructor
       PartTimeEmployee()
       {
          super();
          totalHours = 0;
          totalOT = 0;
       }

       // full constructor
       PartTimeEmployee(String id, String name, String hireDate, double pay, int totalHours, int totalOT)
       {
          super(id, name, hireDate, pay);
          this.totalHours = totalHours;
          this.totalOT = totalOT;
       } 
       //   country of origin accessor
       public int getTotalHours()
       {
          return totalHours;
       }
       public int getTotalOT()
       {
          return totalOT;
       }
       //    overridden getPay() accessor
       public double getPay()
       {
          return(this.getTotalHours()*NORMAL_HOURLY_RATE) + 
                (this.getTotalOT()*(OT_HOURLY_RATE));
        }
}

class Manager extends EmployeeData
{
    Manager[] supervise = new Manager[100];

      //    class variables
      public double groupPay;
      public String addEmployee; 
      public String delEmployee;


     //  default constructor
       Manager()
       {
          super();
          addEmployee = "";
          delEmployee = " ";
          groupPay = 0.0;
       }
       Manager(String id, String name, String hireDate, double pay, double groupPay, String addEmployee, String delEmployee)
       {
       super(id, name, hireDate, pay);
       this.groupPay = groupPay;
       this.addEmployee = addEmployee;
       this.delEmployee = delEmployee;
       }


       public String getAddEmployee(String id, String name, String hireDate, double pay)
       {
        return addEmployee = new;
       }
       public String getDelEmployee(String id, String name, String hireDate, double pay)
       {
         return delEmployee;
       }


       public double getGroupPay()
       {
         return getPay();
       }

}

copied to my pc, compiled, changed

public String getAddEmployee(String id, String name, String hireDate, double pay)
{
    return addEmployee = new;
}

to this:

public String getAddEmployee(String id, String name, String hireDate, double pay)
{
    return addEmployee;
}

seems to work fine. didn't check if it calculates the salary correctly. i probably should check that out. :) otherwise, at first glance it seems to be working fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.