-2

I've got a project looking like this :

public interface Payable{
    double getPaymentAmount(); // calculate payment; no implementation
} // end interface Payable

then I've got an abstract class like this :

    public abstract class Employee implements Payable
    {
       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
// Note: We do not implement Payable method getPaymentAmount here so
// this class must be declared abstract to avoid a compilation error.
    } // end abstract class Employee
`

and the last is a public class inherite Employee like this :

 *public class SalariedEmployee extends Employee*

and the hint error right here:
"error: SalariedEmployee is not abstract and does not override abstract method getPaymentAmount() in Payable public class SalariedEmployee extends Employee "

I don't know where this comes from. This code is taken from a book and should be perfectly fine. I'm using netbean 8.0 and jdk 1.7

jin code
  • 1
  • 1
  • 4
    `"i take from a book and i know it absolutely right"` -- until you've isolated the bug, don't assume anything. Odds are that the error is in your code. Trust me. – Hovercraft Full Of Eels Mar 26 '15 at 13:05
  • 1
    Also, please take the time to indent the code you post. The current code is *really* hard to read. – Jon Skeet Mar 26 '15 at 13:09

4 Answers4

1

You error code says it all. You have to implement every abstract method from your Interface Playable. In this case you are missing the method getPaymentAmount() in your SalariedEmployee class.

EDIT: fixed class

Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107
1

You must implement getPaymentAmount() or in your abstract class (Employee) or in your SalariedEmployee because they implement Payable and this class contain the function getPaymentAmount()

Roy Shmuli
  • 4,979
  • 1
  • 24
  • 38
0

You have to implement each method as requested by the interface (getPaymentAmount()) and by the abstract class definition.

abarisone
  • 3,707
  • 11
  • 35
  • 54
0

Ok I fixed that proplem It just because i am not write all the code of this file he he .So basicly is when the time we write the line

public class SalariedEmployee extends Employee

the hint will appear only we write all the code and add method

public double getPaymentAmount()
{
return getWeeklySalary();
} // end method getPaymentAmount

to our program then the error will disappear .I've got it thank for support. BTW code for file SalariedEmployee.java like this

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
// set salary
public void setWeeklySalary( double salary )
{
if ( salary >= 0.0 ) weeklySalary = salary;
else
throw new IllegalArgumentException(
"Weekly salary must be >= 0.0" );
} // end method setWeeklySalary
// return salary
public double getWeeklySalary()
{
return weeklySalary;
} // end method getWeeklySalary

// calculate earnings; implement interface Payable method that was
// abstract in superclass Employee
@Override
public double getPaymentAmount()
{
return getWeeklySalary();
} // end method getPaymentAmount
@Override
public String toString()
{
return String.format( "salaried employee: %s\n%s: $%,.2f",
super.toString(), "weekly salary", getWeeklySalary() );
} // end method toString
} // end class SalariedEmployee
jin code
  • 1
  • 1