Confused??? Exception problem...
I'm not understanding what I did wrong on this code but here is the code and then the build output.
Code:
public abstract class Employee throws MissingNameException, MissingSSNException
{
/*
* 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
BUILD OUTPUT
Code:
'{' expected
public abstract class Employee throws MissingNameException, MissingSSNException
^
1 error
Process completed
Here is the task view.....
Please help!