Results 1 to 3 of 3
Thread: Confused??? Exception problem...
- 07-06-2011, 08:28 AM #1
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
Confused??? Exception problem...
I'm not understanding what I did wrong on this code but here is the code and then the build output.
BUILD OUTPUTJava 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
Here is the task view.....Java Code:'{' expected public abstract class Employee throws MissingNameException, MissingSSNException ^ 1 error Process completed
Please help!Java Code:'{' expected
- 07-06-2011, 08:49 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What have you tried to fix it? With a glance it looks like you have messed up brackets somewhere.
Also, in some of your methods you throw an exception and immediately catch it, what's the point? You should just throw the exception when necessary, then when you call the method you handle possible exceptions.
This could be wrong, but it's easy to check, try removing the throws from the class and only have the methods contain the throws clause.Last edited by sunde887; 07-06-2011 at 08:52 AM.
- 07-06-2011, 09:15 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Confused in Exception Handling Assignment!!
By rugger06 in forum New To JavaReplies: 5Last Post: 04-10-2011, 02:00 PM -
Exception problem !!
By chathura87 in forum New To JavaReplies: 6Last Post: 02-21-2011, 04:02 PM -
Problem Configuring the JDK (slightly confused)
By lumzi23 in forum New To JavaReplies: 2Last Post: 12-23-2010, 06:12 PM -
Exception handling problem
By computerbum in forum New To JavaReplies: 2Last Post: 04-17-2010, 03:15 PM -
Problem using EBI Webservice getting Exception
By tealc76 in forum Advanced JavaReplies: 0Last Post: 11-21-2009, 06:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks