Don't know why I have an error?
I am getting this error...
Code:
F:\Lab 08\Employee.java:19: unreported exception MissingNameException; must be caught or declared to be thrown
setFirstName( first );
^
F:\Lab 08\Employee.java:20: unreported exception MissingNameException; must be caught or declared to be thrown
setLastName( last );
^
F:\Lab 08\Employee.java:21: unreported exception MissingSSNException; must be caught or declared to be thrown
setSocialSecurityNumber( ssn );
^
3 errors
FOR THIS PROGRAM....
Code:
public abstract class Employee
{
/*
* You will need to add a throws clause to the class header.
* List each of the exceptions that may be thrown by the constructor
*/
private String firstName;
private String lastName;
private String socialSecurityNumber;
// three-argument constructor
public Employee( String first, String last, String ssn )
{
/*
* Before executing each "set" method, test the argument.
* Example: if first is a null string, throw the exception indicatign a missing name,
* else, invoke setFirstName method
*/
setFirstName( first );
setLastName( last );
setSocialSecurityNumber( ssn );
} // end three-argument Employee constructor
// set first name
public void setFirstName( String first ) throws MissingNameException
{
if (first == null)
{
try
{
throw new MissingNameException();
}
catch(MissingNameException missingNameException)
{
System.out.println(missingNameException);
}
}
else
{
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 ) throws MissingNameException
{
if (last == null)
{
try
{
throw new MissingNameException();
}
catch(MissingNameException missingNameException)
{
System.out.println(missingNameException);
}
}
else
{
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 ) throws MissingSSNException
{
if (ssn == null)
{
try
{
throw new MissingSSNException();
}
catch (MissingSSNException missingSSNException)
{
System.out.println(missingSSNException);
}
}
else
{
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
}// end abstract class Employee