Hi I am supposed to modify class employee to implement interface Payable(another class) and declare method getPaymentAmount to invoke method earnings. Method getPaymentAmount would then be inherited by the subclasses in the Employee hierarchy. When getPaymentAmount is called for a particular subclass object, it polymorphically invokes the appropriate earnings method for that subclass. So far I have three errors in the Employee subclasses HourlyEmplyee, CommissionEmployee or BasePlusCommissionEmployee. The key Idea is to correct this errors without necessarily working on the classes themselves but by modifying class employee. Could anyone please help I have no idea on how to go on with the project. I have attached the whole project if you need to reference the other classes. {s/n JAVA RULES!!}

// Fig. 10.4: 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; // should validate
   } // end method setFirstName

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

   // set last name
   public void setLastName( String last )
   {
      lastName = last; // should validate
   } // 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
   @Override
   public String toString()
   {
      return String.format( "%s %s\nsocial security number: %s", 
         getFirstName(), getLastName(), getSocialSecurityNumber() );
   } // end method toString

   // abstract method overridden by concrete subclasses
   public abstract double earnings(); // no implementation here


} // end abstract class Employee

so far I have three errors ...

What errors exactly, on which lines? Please post full error messages and the source code lines where the error happens

It says error parsing files in the Employee subclasses HourlyEmplyee, CommissionEmployee or BasePlusCommissionEmployee.

It says more than that. The stack traces will indicate the exact error and the line it occurs on. Read them carefully.

here is an example of the error in the CommissionEmploye class


cannot find symbol
symbol: constructor CommissionEmployee()
location: class CommissionEmployee
--

Maybe this is the default constructor problem? You don't have a constructor for the subclass, so the compiler tries to supply a default one. The default constructor calls the superclass no-args constructor, but here isn't one so you don't get a default constructor after all, and hence the error message.
Do the subclasses have any constructors defined?

no but the proff wanted us to implement the subclasses ONLY( lol she made that pretty clear) by modifying class employees. could you please sow me an example in code?

>no but...
Yes, CommissionEmployee does have a constructor defined.

>no but...
Yes, CommissionEmployee does have a constructor defined.

so how would you suggest I go about it ?

Re-read what James wrote above about the constructor.

Edit: Looking at the code, the error is actually coming from this constructor definition

BasePlusCommissionEmployee(String string, String string0, String string1, double d) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

I'm not sure what generated that constructor, but I don't think you want to leave it there as is.

I have noticed that the error so how would I create constructors for these subclasses in class employee?

Hint:
If a subclass constructor does not have a call to its superclass constructor as its very first line, the compiler will automatically insert a call the the superclass's default (no args) constructor.
What did the compiler give you in this case? Will that work? If not, what can you do to make it work?

I am saying those constructors probably should not be there at all. A parameter list of (String string, String string0, String string1, double d) looks to be generated from some automated source (introspection of a class file, etc).

You could alleviate the error by creating the necessary zero-argument constructors in the parent classes, but that doesn't address why those auto-generated constructors are there in the first place.

upon deleting the constructors I get this error

cannot find symbol
symbol : constructor HourlyEmployee(java.lang.String,java.lang.String,java.lang.String,double)
location: class HourlyEmployee
(Payable)new HourlyEmployee( "Sally", "McAnna", "985-65-8348", 1200.00 );

Who wrote the entries in PayableInterfaceTest? Did you?

I'm guessing that you had errors on the constructors and used the IDE "Create constructor..." suggestion to "fix it".

yes its exactly as you said

Well, you need to delete all of those constructors then and fix your entries in PayableInterfaceTest to use the valid constructors from those classes. You have used four arguments for all of them. Some require more parameters.

I did some studying and found out how to correct my mistake thanks

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.