Hey guys/gals,
I'm having terrible trouble with my code and I would be most grateful if somebody could point me in the right direction.
First off let me explain my situation. I have a assignment due in Monday morning and I cant make any progress..
The proposal from my lecturer was to create a program with a superclass called employee, a subclass called production worker that has 2 child classes, Team lead and ordinary production worker. I have to be able to input how many workers are working for the team lead and then he will get a bonus based on the "productivity" of the employees he has under him. I was told to do this using arrays so my code is minimal but also so I can add additional TL's when my program is working. I also have to declare the "bonus" as abstract in the employee class so that I can add a supervisor to the mix later on.
I hope I have explained this so that it makes sense to somebody.. below is my code any any help would be wonderful!
//------------------- Employee class------------------------ public abstract class Employee implements Displayable { private double bonus; private int employeeID; public String name; private int startDate; private double pay; private static int count; public abstract double calculateBonus();// NOTE: no body for this method public double getBonus() { calculateBonus(); return bonus; } public void setBonus(double bonus) { this.bonus = bonus; } ////////////////////Constructor///////////////////////////////// public Employee() { employeeID = 1 + count; // start student IDs from 1 count++; //incrementing for each new studentinStudentID; } public Employee(String inName) { employeeID = 1 + count; // start student IDs from 1 count++; //incrementing for each new studentinStudentID; name = inName; } //----------ID--------------- public void setEmployeeID(int ID) { employeeID = ID; } public int getEmployeeID() { return employeeID; } //-------------Name------------ public void setName(String Name) { name = Name; } public String getName() { return name; } //---------Start Date---- public void setStartDate(int DOS) { startDate = DOS; } public int getStartDate() { return startDate; } //------------PAY------------ public void setPay(double pay) { this.pay = pay; } public double getPay() { return pay; } public void display() { System.out.println("Name is " +name); System.out.println("ID is " +employeeID ); System.out.println("the start of work Date " + startDate); } }
//------------------production worker-------------------------- public abstract class ProductionWorker extends Employee { public int totalPay; public double hoursWorked; public int unitsProduced; public int rate; public ProductionWorker() { super(); } public ProductionWorker(String Name) { this.hoursWorked = hoursWorked; } public void sethoursWorked(double hourWorked) { this.hoursWorked = hoursWorked; } public double gethoursWorked() { return hoursWorked; } public void setUnitsProduced(int unitsProduced) { this.unitsProduced = unitsProduced; } public double getUnitsProduced() { return unitsProduced; } public void totalPay() { setPay(hoursWorked * rate); } public double gettotalPay() { return totalPay; } public void display() { super.display(); System.out.println("The total income of the day: " +gettotalPay()); } }
//---------------------Ordinary production--------------------------------- public abstract class OrdinaryProduction extends ProductionWorker { private double productivity; private double wages; public OrdinaryProduction() { super(); } ////////////////////////////////////////////////////////////////// // Modifier methods - used to set values for instance variables public void setUnitsProduced(int UP) { unitsProduced = UP; } public double getUnitsProduced() { return unitsProduced; } public void setProductivity(int Productivity) { productivity = Productivity; } public double getProductivity() { return productivity; } ///////////////////////////////////////////////////////////////////// // Accessor methods - used to retrieve values for instance variables public void calcWages() // Sub-class implements abstract method from the ProductionWorker class { setWages(hoursWorked * 12); } public double getWages() { return wages; } //////////////////////////////////////////////////////////////// // Method to determine the productivity - this is called a helper method // A helper method is one that is invoked within a class but is // not visible outside of the class private void calculateProductivity() { if( unitsProduced >=4 ) productivity = 'A'; else if( unitsProduced >= 3) productivity = 'B'; else if( unitsProduced >= 2) productivity = 'C'; else if( unitsProduced >= 1) productivity = 'D'; else productivity = 'E'; } //////////////////////////////////////////////////////////////// // Method to display information public void display() { System.out.println("Weekly wages :" + wages); System.out.println("Weekly wages :" + productivity); } }
//----------------------Team lead---------------------- public class TeamLead extends OrdinaryProduction { private int unitsProduced; private int productivity; private int workers; private double wages; private OrdinaryProduction[amount]; public TeamLead() {} /////////////////////////////////////// //Set array to read in production workers setOpwArray(OrdinaryProduction[] op){ //OrdinaryProductionWorkerArray = opwArray; } public int getOpwArray(OrdinaryProduction[] op) { return op; } ////////////////////////////////////////////////////////////////// // Modifier methods - used to set values for instance variables public void sethoursWorked(int inHoursWorked) { hoursWorked = inHoursWorked; } public void setWages(double inWages) { wages = inWages; } public void setWorkers(int inWorkers) { workers = inWorkers; } public void setWages(int inWages) { wages = inWages; } ///////////////////////////////////////////////////////////////////// // Accessor methods - used to retrieve values for instance variables public int getHoursWorked() { return hoursWorked; } public int getWorkers() { return workers; } public int getProductivity() { return productivity; } public void calcBonus() { if (productivity = A) bonus = 700; else if( productivity = B) bonus = 500; else if( unitsProduced = C) bonus = 200; else if( unitsProduced = D) bonus = 100; else bonus = 0; } public void calcWages() // Sub-class implements abstract method from the Employee class { setWages(hoursWorked * 13.80); } }
//----------------------------Employee info------------------------- class EmployeeInformation { public static void main (String [] args ){ Scanner input = new Scanner(System.in); TeamLead TL1 = new TeamLead(); System.out.print("How many Production workers working for TL1 ?"); int amount = input.nextInt(); OrdinaryProduction[] opwArray = new OrdinaryProduction[amount]; for (int i = 0; i < opwArray.length; i++){ opwArray[i] = new OrdinaryProduction(); System.out.print("Enter name for production worker?"); opwArray[i].setName(input.nextLine()); System.out.print("Enter Start date for production worker?"); opwArray[i].setStartDate(input.nextInt()); System.out.print("Enter hours worked for production worker?"); opwArray[i].sethoursWorked(input.nextInt()); System.out.print("Enter units produced for production worker?"); opwArray[i].setunitsProduced(input.nextInt()); System.out.print("Enter productivity for production worker?"); opwArray[i].setproductivity(input.nextInt()); } } }