Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

I need help with this Employee project?

I have a problem in the ProductionWorker and ShiftSuperVisor. I can't assign my own value in the class.

Employee:

import java.util.Random;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Employee
{
    protected String eName;
   protected String eNumber;
    protected int hireYear;
    protected double weeklySalary;
    static Random generator = new Random();
    static  NumberFormat format = new DecimalFormat("#####.##");;

   
    public Employee(String eName,String eNumber,int hireYear, double weeklySalary)
    {
       
        this.eName = eName;
        if(validateENumber(eNumber))
        {
           
            this.eNumber = eNumber;
        }
            else
                employeeNumber();
           
       
        this.hireYear = hireYear;
       
        this.weeklySalary = weeklySalary;
       
    }
   
    public Employee(String eName,String eNumber,int hireYear)
    {
       
        this.eName = eName;
        if(validateENumber(eNumber))
        {
           
            this.eNumber = eNumber;
        }
            else
                employeeNumber();
           
       
        this.hireYear = hireYear;
       
       
    }
   
   public boolean validateENumber(String eNumber)
    {
        boolean validate = true;
        if(eNumber.length() < 5)
        validate = false;
        else{
        for (int i = 0; i < 3; i++)
        {
           if(!Character.isDigit(eNumber.charAt(i)))
           {
               validate = false;
            }
        }
        if (!(eNumber.charAt(3) == '-'))
            validate = false;
           
        if (!((eNumber.charAt(4) >= 65) && (eNumber.charAt(4) <=77)))
            validate = false;
           
       
    }
    return validate;
}
   
    public int getHireYear()
        {
            return hireYear;
        }
       
    public double getWeeklypay()
        {
            return weeklySalary;
        }
       
    public void setName(String name)
        {
            eName = name;
        }
       
    public void setHireYear(int year)
        {
            hireYear = year;
        }
       
    public void setWeeeklyPay(int salary)
        {
            weeklySalary = salary;
        }
       
    public String getName()
    {
        return eName;
    }
     public String toString()
    {
        return (eName + "," + employeeNumber() + "," + hireYear + "," + weeklySalary);

    }
   
    public String getNumber()
    {
        return eNumber;
    }
 
   public static String employeeNumber()
    {
        int  eNumber = generator.nextInt(10)* 100 + generator.nextInt(10)* 10 + generator.nextInt(10);
        String enumS = "" + eNumber;
        while(enumS.length() < 3)
        enumS = "0" + enumS;
        String let = "" + ("ABCDEFGHIJKLM").charAt(generator.nextInt(13));
        return enumS + "-" + let;
    }

    public boolean equals(Employee other)
    {
       
       if ((eName.equals(other.getName())) && (eNumber.equals(other.getNumber())) && (hireYear == other.getHireYear()) && (weeklySalary == other.getWeeklypay()))
            return true;
       else
            return false;

    }
}

ProductionWorker:

public class ProductionWorker extends Employee
{
    //value of how much a production worker makes hourly
    protected static double hourlySalary = 50.00;
   
   
   
    //constructor that calls variables from Class Employee to create object ProductionWorker
    public ProductionWorker(String eName,String eNumber,int hireYear, double hourlySalary)
    {
        super(eName,eNumber,hireYear);
        if(super.validateENumber(eNumber))
        {
           
            this.eNumber = eNumber;
        }
            else
                super.employeeNumber();
        this.hourlySalary = hourlySalary;
    }
   

    public double getHourlySalary()
        {
            return hourlySalary;
        }

    public void setHourlySalary(double salary)
        {
            this.hourlySalary = salary;
        }
   
   
    public String toString()
    {
        return (eName + "," + super.employeeNumber() + "," + hireYear + "," + weeklySalary);

    }

     /**
     * Equals method
     */
    public boolean equals(ProductionWorker worker)
    {
        if(hourlySalary == worker.getHourlySalary())
        return true;
       
        return false;
    }
   
     public String getSalary()
    {
    String perSalary ="$" + hourlySalary + " per Hour";
    return perSalary;
    }
}

ShiftSuperVisor:


public class ShiftSuperVisor extends Employee
{
    // instance variables - replace the example below with your own
    protected static double yearlySalary = 80000.00;
    protected int goal;

    /**
     * Constructor for objects of class ShiftSuperVisor
     */
    public ShiftSuperVisor(String eName,String eNumber,int hireYear,
    double yearlySalary, int goals)
    {
        super(eName,eNumber,hireYear);
        if(super.validateENumber(eNumber))
        {
           
            this.eNumber = eNumber;
        }
            else
                super.employeeNumber();
        this.yearlySalary = yearlySalary;
        goal = goals;
    }

    public double getYearlySalary()
        {
            return yearlySalary;
        }

    public void setYearlySalary(double salary)
        {
            this.yearlySalary = salary;
        }
       
    public void setGoal(int goal)
    {
        this.goal = goal;
    }
   
    public int getGoal()
    {
        return goal;
    }
   
    public String toString()
    {
         return (eName + "," + super.employeeNumber() + "," + hireYear + "," + weeklySalary + "," + yearlySalary);
        }

     /**
     * Equals method
     */
    public boolean equals(ShiftSuperVisor visor)
    {
        if(goal == visor.getGoal())
        if(yearlySalary == visor.getYearlySalary())
        return true;
       
        return false;
       
    }
   
    public String getSalary()
    {
    String perSalary ="$" + yearlySalary + " per Year";
    return perSalary;
    }
}


0
ryanbecker24
Asked:
ryanbecker24
  • 8
  • 4
1 Solution
 
for_yanCommented:
Where is your main() method?
0
 
ryanbecker24Author Commented:
I am using BlueJ so I don't need one. It compiles it just doesn't work the way I want it to
0
 
for_yanCommented:
I don't know how to excute it - it does compile, but I don't know waht to do with it.
What does your BlueJ do to execute it? Do you specify some method to start?

Don't use this strange thing
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
for_yanCommented:
Maybe you don't want to use protected restrictions - remove all of them and try.

Still, BlueJ or not BlueJ - it needs to know where to start executing
0
 
for_yanCommented:

So how do you start executing it:
http://facweb.cs.depaul.edu/noriko/howto-bluej.html

Do you select some method and run this method - what it is that uyou are doing to run it?
0
 
ryanbecker24Author Commented:
For my employee class, the program asks me to type in things for the parameters. If I type the eNumber in the format XXX-L where XXX goes from 0-999 and L is A-M. If I don't type in that format it creates a random eNumber. For example if I type in 999-Z it would give me a random number like 555-A. But for ShiftSuperVisor and ProductionWorker, if I type in 555-A it doesn't give me 555-A it could give me a random number something like 043-L when I call the toString() method.
0
 
ryanbecker24Author Commented:
I create the object and it goes to the object bench. When I call the method toString() method from the object bench it doesn't give me the value I want.
0
 
for_yanCommented:
try to replace ProductionWorker with this:

public class ProductionWorker extends Employee
{
    //value of how much a production worker makes hourly
    protected static double hourlySalary = 50.00;



    //constructor that calls variables from Class Employee to create object ProductionWorker
    public ProductionWorker(String eName,String eNumber,int hireYear, double hourlySalary)
    {
        super(eName,eNumber,hireYear);
        if(super.validateENumber(eNumber))
        {

            this.eNumber = eNumber;
        }
            else
               this.eNumber =  employeeNumber();
        this.hourlySalary = hourlySalary;
    }


    public double getHourlySalary()
        {
            return hourlySalary;
        }

    public void setHourlySalary(double salary)
        {
            this.hourlySalary = salary;
        }


    public String toString()
    {
        return (eName + "," + eNumber + "," + hireYear + "," + weeklySalary);

    }

     /**
     * Equals method
     */
    public boolean equals(ProductionWorker worker)
    {
        if(hourlySalary == worker.getHourlySalary())
        return true;

        return false;
    }

     public String getSalary()
    {
    String perSalary ="$" + hourlySalary + " per Hour";
    return perSalary;
    }
}

Open in new window

0
 
for_yanCommented:
replace both of them:

public class ProductionWorker extends Employee
{
    //value of how much a production worker makes hourly
    protected static double hourlySalary = 50.00;



    //constructor that calls variables from Class Employee to create object ProductionWorker
    public ProductionWorker(String eName,String eNumber,int hireYear, double hourlySalary)
    {
        super(eName,eNumber,hireYear);
        if(super.validateENumber(eNumber))
        {

            this.eNumber = eNumber;
        }
            else
               this.eNumber =  Employee.employeeNumber();
        this.hourlySalary = hourlySalary;
    }


    public double getHourlySalary()
        {
            return hourlySalary;
        }

    public void setHourlySalary(double salary)
        {
            this.hourlySalary = salary;
        }


    public String toString()
    {
        return (eName + "," + eNumber + "," + hireYear + "," + weeklySalary);

    }

     /**
     * Equals method
     */
    public boolean equals(ProductionWorker worker)
    {
        if(hourlySalary == worker.getHourlySalary())
        return true;

        return false;
    }

     public String getSalary()
    {
    String perSalary ="$" + hourlySalary + " per Hour";
    return perSalary;
    }
}




 public class ShiftSuperVisor extends Employee
{
    // instance variables - replace the example below with your own
    protected static double yearlySalary = 80000.00;
    protected int goal;

    /**
     * Constructor for objects of class ShiftSuperVisor
     */
    public ShiftSuperVisor(String eName,String eNumber,int hireYear,
    double yearlySalary, int goals)
    {
        super(eName,eNumber,hireYear);
        if(super.validateENumber(eNumber))
        {

            this.eNumber = eNumber;
        }
            else
              this.eNumber = Employee.employeeNumber();
        this.yearlySalary = yearlySalary;
        goal = goals;
    }

    public double getYearlySalary()
        {
            return yearlySalary;
        }

    public void setYearlySalary(double salary)
        {
            this.yearlySalary = salary;
        }

    public void setGoal(int goal)
    {
        this.goal = goal;
    }

    public int getGoal()
    {
        return goal;
    }

    public String toString()
    {
         return (eName + "," + eNumber + "," + hireYear + "," + weeklySalary + "," + yearlySalary);
        }

     /**
     * Equals method
     */
    public boolean equals(ShiftSuperVisor visor)
    {
        if(goal == visor.getGoal())
        if(yearlySalary == visor.getYearlySalary())
        return true;

        return false;

    }

    public String getSalary()
    {
    String perSalary ="$" + yearlySalary + " per Year";
    return perSalary;
    }
}

Open in new window

0
 
ryanbecker24Author Commented:
Yeah that worked. Can you do the same to ShiftSuperVisor please?
0
 
for_yanCommented:
Actually I don't understand how Employee could have been working
I think your problem is in the toString() method

return (eName + "," + employeeNumber() + "," + hireYear + "," + weeklySalary);

Open in new window


you should not run  employeeNumber()  method which generates random number
every time you call toString()

You shoueld rather do this:

return (eName + "," + eNumber+ "," + hireYear + "," + weeklySalary);

Open in new window


It should use its stored field eNumber in toString()
then it will print you eNumber as a property of particular instance of the class
If you would be running eNumber generation every time you
call toString() then you'll get different eNumber values
every time you run toString() on the same instance - this should be changed in all three
of them.

You need to run this generation only once in the constructor - when you generate new instance




0
 
for_yanCommented:
see above i changed shiftsupervisor also
You should change Employee also
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now