Hi everyone,
My classes are: Employee, Date and HourlyEmployee. I'm supposed to write my Employee class with Date class as an Inner class and then HourlyEmployee is supposed to extend Employee. Class Date has 3 attributes, day, month, and year are all int values except month may be written as a string, these values are set to default of "January 1, 1000" when the default constructor is invoked. Class Employee had 2 attributes, name and Date. name is inputted by the user, date is also inputted by the user but once input is received, date values are sent to other methods to verify if the date information is correct. HourlyEmployee is exactly like Employee except with additional attributes or wageRate and hoursWorked, both int values.
I have rewritten Date inside Employee and when i create an Employee object in my main, everything works perfectly. My Date class has a method to prompt user for input, called readInput(), and will automatically set the Employee date to the input values given by the user. Where i am having trouble is when i create an HourlyEmployee object and try to access the same readInput() method, the values entered do not actually get set to the object, so i am able to input values for HourlyEmployee object but when i print my object's attributes, the default values of Date object show up instead. Maybe i'm not calling the readInput() from HourlyEmployee correctly? (my classes all have mutator methods, just not shown here)
public class Employee
{
protected class Date
private String month;
private int day;
private int year; //a four digit number.
public Date( )
{
month = "January";
day = 1;
year = 1000;
} //sets the default date to January 1, 1000
other methods...
public void readInput( ) //method that prompts the user for input
//automatically verifies if the date is correct by
//calling other functions is class Date
{
boolean tryAgain = true;
Scanner keyboard = new Scanner(System.in);
while (tryAgain)
{
System.out.print("Enter month, day, and year, do not use a comma: ");
String monthInput = keyboard.next( );
int dayInput = keyboard.nextInt( );
int yearInput = keyboard.nextInt( );
if (dateOK(monthInput, dayInput, yearInput) )
{
setDate(monthInput, dayInput, yearInput);
tryAgain = false;
}
else
System.out.println("Illegal date. Reenter input.");
}
}
}//end of class Date
}//end of class Employee
public class HourlyEmployee extends Employee
{
private double wageRate;
private double hours; //for the month
public HourlyEmployee( )
{
super( );
wageRate = 0;
hours = 0;
}
more methods...
}//end of class HourlyEmployee
So basically, im not quite sure how i should be calling Date class when i create an HourlyEmployee Object.
The way that i'm currently doing it is:
HourlyEmployee e = new HourlyEmployee(); //creating an hourlyemployee
//i am trying to call readInput() from Date class so i'm saying:
e.getHireDate().readInput(); //which is the only way i can get the function
// to work and its supposed to prompt user
//for input and set the object to those values
//and it's not
am i calling the inner class Date correctly using HourlyEmployee object? it compiles without problem but the code is not working as it should
any suggestions?
thank you VERY much