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
   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
5 Years
Discussion Span
Last Post by carlitosway17

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?

Edited by carlitosway17: n/a


>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.

Edited by Ezzaral: n/a


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

Edited by carlitosway17: n/a


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".


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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.