Hello,

I had put this question in another thread and I got a response that seemed to explain it well but I just seem to keep going in circles and I'm still just not getting it. So I need some more help. The other thread started getting pretty lengthy so I just started a new one. Here's what I am supposed to do:

In addition you need to add a new private instance field "birthDate" to the Employee class. Add get and set methods to Employee class for this new birthDate field. The birthdate is to be displayed using a customized toDateString method in the Date class. The birthDate field must be determined from separate integer values, supplied by the user, for the month, day, and year. These three parameter values should be supplied to a modified Employee class constructor, where the single birthDate field is initialized.

Here is the ORIGINAL Employee superclass code:

// Employee.java
// Employee abstract superclass.

public abstract class Employee 
{
   private String firstName;
   private String lastName;
   private String socialSecurityNumber;

   // three-argument constructor
   public Employee( String first, String last, String ssn )
   {
      firstName = first;
      lastName = last;
      socialSecurityNumber = ssn;
   } // end three-argument Employee constructor

   // set first name
   public void setFirstName( String first )
   {
      firstName = first;
   } // end method setFirstName

   // return first name
   public String getFirstName()
   {
      return firstName;
   } // end method getFirstName

   // set last name
   public void setLastName( String last )
   {
      lastName = last;
   } // end method setLastName

   // return last name
   public String getLastName()
   {
      return lastName;
   } // end method getLastName

   // set social security number
   public void setSocialSecurityNumber( String ssn )
   {
      socialSecurityNumber = ssn; // should validate
   } // end method setSocialSecurityNumber

   // return social security number
   public String getSocialSecurityNumber()
   {
      return socialSecurityNumber;
   } // end method getSocialSecurityNumber

   // return String representation of Employee object
   public String toString()
   {
      return String.format( "%s %s\nsocial security number: %s", 
         getFirstName(), getLastName(), getSocialSecurityNumber() );
   } // end method toString

   // abstract method overridden by subclasses
   public abstract double earnings(); // no implementation here
} // end abstract class Employee

Here is the ORIGINAL Date class:

// Date.java 
// Date class declaration.

public class Date 
{
   private int month; // 1-12
   private int day;   // 1-31 based on month
   private int year;  // any year

   // constructor: call checkMonth to confirm proper value for month; 
   // call checkDay to confirm proper value for day
   public Date( int theMonth, int theDay, int theYear )
   {
      month = checkMonth( theMonth ); // validate month
      year = theYear; // could validate year
      day = checkDay( theDay ); // validate day

      System.out.printf( 
         "Date object constructor for date %s\n", this );
   } // end Date constructor

   // utility method to confirm proper month value
   private int checkMonth( int testMonth )
   {
      if ( testMonth > 0 && testMonth <= 12 ) // validate month
         return testMonth;
      else // month is invalid 
      { 
         System.out.printf( 
            "Invalid month (%d) set to 1.", testMonth );
         return 1; // maintain object in consistent state
      } // end else
   } // end method checkMonth

   // utility method to confirm proper day value based on month and year
   private int checkDay( int testDay )
   {
      int daysPerMonth[] = 
         { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
   
      // check if day in range for month
      if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
         return testDay;
   
      // check for leap year
      if ( month == 2 && testDay == 29 && ( year % 400 == 0 || 
           ( year % 4 == 0 && year % 100 != 0 ) ) )
         return testDay;
   
      System.out.printf( "Invalid day (%d) set to 1.", testDay );
      return 1;  // maintain object in consistent state
   } // end method checkDay
   
   // return a String of the form month/day/year
   public String toString()
   { 
      return String.format( "%d/%d/%d", month, day, year ); 
   } // end method toString
} // end class Date

And here are my modified versions of the Employee and Date classes. They build fine but when I try to use them with my main class, it seems obvious that I've still done something wrong. (I get something like a "no such method exists" message when I run it.) Can anyone help me?

// Employee.java
// Employee abstract superclass.

public abstract class Employee 
{
   private String firstName;
   private String lastName;
   private String socialSecurityNumber;
	private String birthDate;

   // three-argument constructor
   public Employee( String first, String last, String ssn, String date, int month, int day, int year )
   {
      firstName = first;
      lastName = last;
      socialSecurityNumber = ssn;
		birthDate = date;
   } // end three-argument Employee constructor

   // set first name
   public void setFirstName( String first )
   {
      firstName = first;
   } // end method setFirstName

   // return first name
   public String getFirstName()
   {
      return firstName;
   } // end method getFirstName

   // set last name
   public void setLastName( String last )
   {
      lastName = last;
   } // end method setLastName

   // return last name
   public String getLastName()
   {
      return lastName;
   } // end method getLastName

   // set social security number
   public void setSocialSecurityNumber( String ssn )
   {
      socialSecurityNumber = ssn; // should validate
   } // end method setSocialSecurityNumber

   // return social security number
   public String getSocialSecurityNumber()
   {
      return socialSecurityNumber;
   } // end method getSocialSecurityNumber
	
	public void setBirthDate( String date)
	{
		birthDate = date;
	}

	public String getBirthDate()
	{
		return birthDate;
	}

   // return String representation of Employee object
   public String toString()
   {
      return String.format( "%s %s\nsocial security number: %s\nBirthdate: %s", 
         getFirstName(), getLastName(), getSocialSecurityNumber(), getBirthDate() );
   } // end method toString

   // abstract method overridden by subclasses
   public abstract double earnings(); // no implementation here
} // end abstract class Employee
public class Date 
{
   private int month; // 1-12
   private int day;   // 1-31 based on month
   private int year;  // any year
	
   // constructor: call checkMonth to confirm proper value for month; 
   // call checkDay to confirm proper value for day
   public Date( int theMonth, int theDay, int theYear )
   {
      month = checkMonth( theMonth ); // validate month
      year = theYear; // could validate year
      day = checkDay( theDay ); // validate day

      System.out.printf( 
         "Date object constructor for date %s\n", this );
   } // end Date constructor

   // utility method to confirm proper month value
   private int checkMonth( int testMonth )
   {
      if ( testMonth > 0 && testMonth <= 12 ) // validate month
         return testMonth;
      else // month is invalid 
      { 
         System.out.printf( 
            "Invalid month (%d) set to 1.", testMonth );
         return 1; // maintain object in consistent state
      } // end else
   } // end method checkMonth

   // utility method to confirm proper day value based on month and year
   private int checkDay( int testDay )
   {
      int daysPerMonth[] = 
         { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
   
      // check if day in range for month
      if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
         return testDay;
   
      // check for leap year
      if ( month == 2 && testDay == 29 && ( year % 400 == 0 || 
           ( year % 4 == 0 && year % 100 != 0 ) ) )
         return testDay;
   
      System.out.printf( "Invalid day (%d) set to 1.", testDay );
      return 1;  // maintain object in consistent state
   } // end method checkDay
   
   // return a String of the form month/day/year
   public String toString()
   { 
      return String.format( "%d/%d/%d", month, day, year ); 
   }// end method toString
	
	public String toDateString(String birthDate)
	{
		return String.format( "Birthdate: %d/%d/%d", month, day, year );
	}


	
} // end class Date

You need to post the line that you get the error. The error messages, indicates the line that it happened as well as the file.

You need to post the line that you get the error. The error messages, indicates the line that it happened as well as the file.

Here's what it tells me when I run it:

----jGRASP exec: java PayrollSystemTest

Exception in thread "main" java.lang.NoSuchMethodError: Employee.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
at SalariedEmployee.<init>(SalariedEmployee.java:12)
at PayrollSystemTest.main(PayrollSystemTest.java:96)

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

Here's what it tells me when I run it:

----jGRASP exec: java PayrollSystemTest

Exception in thread "main" java.lang.NoSuchMethodError: Employee.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
at SalariedEmployee.<init>(SalariedEmployee.java:12)
at PayrollSystemTest.main(PayrollSystemTest.java:96)

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

Oops, it thought that something I pasted from the error message was an emoticon. LOL Anyway, I looked at where that error occurs and this is a piece of that class's code that it occurs in, well, the error in the SalariedEmployee class. I still have to look at the other one.

// SalariedEmployee.java
// SalariedEmployee class extends Employee.

public class SalariedEmployee extends Employee 
{
   private double weeklySalary;

   // four-argument constructor
   public SalariedEmployee( String first, String last, String ssn, 
      double salary )
   {
      super( first, last, ssn ); // pass to Employee constructor
      setWeeklySalary( salary ); // validate and store salary
   } // end four-argument SalariedEmployee constructor

The exact line it occurs in is:

super( first, last, ssn ); // pass to Employee constructor

I would imagine this is because I don't have my Employee constructor written correctly for what I need the program to do.

super, calls the constructor of the super class and in this case the Employee class:

public SalariedEmployee( String first, String last, String ssn, ... {
    [U]super( first, last, ssn );[/U]

}

Does the Employee has a constructor that takes as parameters 3 Strings.

super, calls the constructor of the super class and in this case the Employee class:

public SalariedEmployee( String first, String last, String ssn, ... {
    [U]super( first, last, ssn );[/U]

}

Does the Employee has a constructor that takes as parameters 3 Strings.

It did have only that. I was given a code to modify and, for the Employee constructor, this is what I started with:

public Employee( String first, String last, String ssn )
   {
      firstName = first;
      lastName = last;
      socialSecurityNumber = ssn;
   }

Since I've modified it to do what it is supposed to do which is:

"You need to add a new private instance field "birthDate" to the Employee class. Add get and set methods to Employee class for this new birthDate field. The birthdate is to be displayed using a customized toDateString method in the Date class. The birthDate field must be determined from separate integer values, supplied by the user, for the month, day, and year. These three parameter values should be supplied to a modified Employee class constructor, where the single birthDate field is initialized."

It looks like this:

public Employee( String first, String last, String ssn, String date, int month, int day, int year )
   {
      firstName = first;
      lastName = last;
      socialSecurityNumber = ssn;
		birthDate = date;
   }

I'm almost positive that I've messed up with my Employee constructor and probably with my date class too, which looks like this so far:

public class Date 
{
   private int month; // 1-12
   private int day;   // 1-31 based on month
   private int year;  // any year
	
   // constructor: call checkMonth to confirm proper value for month; 
   // call checkDay to confirm proper value for day
   public Date( int theMonth, int theDay, int theYear )
   {
      month = checkMonth( theMonth ); // validate month
      year = theYear; // could validate year
      day = checkDay( theDay ); // validate day

      System.out.printf( 
         "Date object constructor for date %s\n", this );
   } // end Date constructor

   // utility method to confirm proper month value
   private int checkMonth( int testMonth )
   {
      if ( testMonth > 0 && testMonth <= 12 ) // validate month
         return testMonth;
      else // month is invalid 
      { 
         System.out.printf( 
            "Invalid month (%d) set to 1.", testMonth );
         return 1; // maintain object in consistent state
      } // end else
   } // end method checkMonth

   // utility method to confirm proper day value based on month and year
   private int checkDay( int testDay )
   {
      int daysPerMonth[] = 
         { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
   
      // check if day in range for month
      if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
         return testDay;
   
      // check for leap year
      if ( month == 2 && testDay == 29 && ( year % 400 == 0 || 
           ( year % 4 == 0 && year % 100 != 0 ) ) )
         return testDay;
   
      System.out.printf( "Invalid day (%d) set to 1.", testDay );
      return 1;  // maintain object in consistent state
   } // end method checkDay
   
   // return a String of the form month/day/year
   public String toString()
   { 
      return String.format( "%d/%d/%d", month, day, year ); 
   }// end method toString
	
	public String toDateString(String birthDate)
	{
		return String.format( "Birthdate: %d/%d/%d", month, day, year );
	}


	
} // end class Date

You changed the contructor of the Employee class. So it is normal that you get an error when you try to call the old constructor: super(String, String, String) .
Such contructor with 3 arguments does not exist. The new takes 6 arguments.
So the new is this:

public Employee( String first, String last, String ssn, String date, int month, int day, int year ) {

}

But you are calling this:

public SalariedEmployee( String first, String last, String ssn, 
      double salary )
   {
      [B]super( first, last, ssn );[/B] // pass to Employee constructor
      setWeeklySalary( salary ); // validate and store salary
   }

You changed the contructor of the Employee class. So it is normal that you get an error when you try to call the old constructor: super(String, String, String) .
Such contructor with 3 arguments does not exist. The new takes 6 arguments.
So the new is this:

public Employee( String first, String last, String ssn, String date, int month, int day, int year ) {

}

But you are calling this:

public SalariedEmployee( String first, String last, String ssn, 
      double salary )
   {
      [B]super( first, last, ssn );[/B] // pass to Employee constructor
      setWeeklySalary( salary ); // validate and store salary
   }

I have modified the code to what it is at the moment and I know I haven't modified it correctly. I know for certain that I'm supposed to ONLY have to modify the Date class and the Employee class to include a formatted date to be used for all the sublclasses of the Employee class. The problem is, I'm stuck on the correct way to modify those two classes to make it do that. Here are my instructions for this part of the program:

"you need to add a new private instance field "birthDate" to the Employee class. Add get and set methods to Employee class for this new birthDate field. The birthdate is to be displayed using a customized toDateString method in the Date class. The birthDate field must be determined from separate integer values, supplied by the user, for the month, day, and year. These three parameter values should be supplied to a modified Employee class constructor, where the single birthDate field is initialized."

In a different thread, someone told me that this is easy and that these instructions tell me step by step what do but I'm still having trouble understanding exactly HOW to do these steps. I think I've been going around in circles on other parts of the program so long that I'm missing something very simple for this part but the fact is, I AM missing something and my brain is fried by now! How should I be trying to modify the Date and Employee class to include a formatted date in my program?

(You can see the original code that I started with in the very first two codes I posted at the beginning of this thread.)

And I already told you what to do. You have declared a constructor (Employee) with 6 arguments and you are not calling it. You are calling it with 3 arguments.
It is very basic. When you have a method with a certain number of arguments, you call that method with the right type and amount of arguments.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.