Inheritance code returns no value

I created a super class called Employee, with a subclass called ProductionWorker and a driver called ProductionWorkerDriver. The program takes my entered info and returns the String values from the Employee class, but not the double and int values from the ProductionWorker class. The program I'm using said I had to initialize the values of those as 0, and I'm thinking that's why they show up as zero when compiled. However, the program won't compile without that, so I'm not sure what to do.

public class Employee {
    private String name;
    private String employeeNumber;
    private String hireDate;

    public Employee(String n, String num, String date) {
        name = n;
        employeeNumber = num;
        hireDate = date;
    }

    public Employee() {
        name = "";
        employeeNumber = "";
        hireDate = "";
    }

    public void setName(String n) {
        name = n;
    }

    public void setEmployeeNumber(String e) {
        employeeNumber = e;
    }

    public void setHireDate(String h) {
        hireDate = h;
    }

    public String getName() {
        return name;

    }

    public String getEmployeeNumber() {
        return employeeNumber;
    }

    public String getHireDate() {
        return hireDate;
    }

    public String toString() {
        String str = "Employee Name: " + name
                + "\nEmployee #: " + employeeNumber
                + "\nHire Date: " + hireDate;

        return str;

    }
} //end of Employee class


//beginning of ProductionWorker class
import java.text.DecimalFormat;

public class ProductionWorker extends Employee {
    private int shift;
    private double payRate;
    public int DAY_SHIFT = 1;
    public int NIGHT_SHIFT = 2;

    public ProductionWorker(String n, String num, String date, int sh, double rate) {
        super(n, num, date);
        shift = sh;
        payRate = rate;

    }

    public ProductionWorker() {

    }

    public void setShift(int s) {
        shift = s;
    }

    public void setPayRate(double p) {
        payRate = p;
    }

    public int getShift() {
        return shift;
    }

    public double getPayRate() {
        return payRate;
    }

    public String toString() {
        DecimalFormat dollar = new DecimalFormat("#,##0.00");

        String str = super.toString() + "\nShift: " + shift
                + "\nPay Rate: $" + dollar.format(payRate);

        return str;
    }
}//end of ProductionWorker class


//beginning of ProductionWorkerDriver
import java.util.Scanner;

public class ProductionWorkerDriver {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);

        String name = null;
        String employeeNumber = null;
        String hireDate = null;
        int shift = 0;
        double payRate = 0;
        int DAY_SHIFT = 1;
        int NIGHT_SHIFT = 2;

        Employee info = new Employee(name, employeeNumber, hireDate);

        System.out.println("Employee Name:");
        name = keyboard.nextLine();

        System.out.println("Employee #:");
        employeeNumber = keyboard.nextLine();

        System.out.println("Hire Date:");
        hireDate = keyboard.nextLine();

        ProductionWorker info2 = new ProductionWorker(name, employeeNumber, hireDate, shift, payRate);

        System.out.println("Shift 1 or 2:");
        shift = keyboard.nextInt();

        System.out.println("Pay Rate:");
        payRate = keyboard.nextDouble();

        System.out.println(info2.toString());

    }

}//end of ProductionWorkerDriver
Jon Skeet
people
quotationmark

You're not doing anything with the data you've entered:

System.out.println("Shift 1 or 2:");
shift = keyboard.nextInt();

System.out.println("Pay Rate:");
payRate = keyboard.nextDouble();

... the shift and payRate variables aren't used again. Changing the values of these local variables doesn't change the values in the instance that you created earlier using the same variables.

You should either be calling:

info2.setShift(shift);
info2.setPayRate(payRate);

... or better, wait until after you've asked those questions before you construct the instance. You're also not using your info variable at all. Your entire main method can be improved to:

Scanner keyboard = new Scanner(System.in);

System.out.println("Employee Name:");
String name = keyboard.nextLine();

System.out.println("Employee #:");
String employeeNumber = keyboard.nextLine();

System.out.println("Hire Date:");
String hireDate = keyboard.nextLine();

System.out.println("Shift 1 or 2:");
int shift = keyboard.nextInt();

System.out.println("Pay Rate:");
double payRate = keyboard.nextDouble();

ProductionWorker worker = 
    new ProductionWorker(name, employeeNumber, hireDate, shift, payRate);

System.out.println(worker);

Notice how in each case we don't declare a variable until we need it.

Note that the fact that your employee number and your hire date are both String values is a bit of a worry, and it's a bad idea to use double for currency values - get into the habit of using BigDecimal, or use an integer to represent a number of cents/pennies/whatever.

people

See more on this question at Stackoverflow