Avatar of ryanbecker24
ryanbecker24

asked on 

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;
    }
}


Java

Avatar of undefined
Last Comment
for_yan
Avatar of for_yan
for_yan
Flag of United States of America image

Where is your main() method?
Avatar of ryanbecker24
ryanbecker24

ASKER

I am using BlueJ so I don't need one. It compiles it just doesn't work the way I want it to
Avatar of for_yan
for_yan
Flag of United States of America image

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
Avatar of for_yan
for_yan
Flag of United States of America image

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
Avatar of for_yan
for_yan
Flag of United States of America image


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?
Avatar of ryanbecker24
ryanbecker24

ASKER

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.
Avatar of ryanbecker24
ryanbecker24

ASKER

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.
Avatar of for_yan
for_yan
Flag of United States of America image

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

Avatar of for_yan
for_yan
Flag of United States of America image

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

Avatar of ryanbecker24
ryanbecker24

ASKER

Yeah that worked. Can you do the same to ShiftSuperVisor please?
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of for_yan
for_yan
Flag of United States of America image

see above i changed shiftsupervisor also
You should change Employee also
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo