Instructions: Answer as many of the following questions as you can during the lab period. If you are unable to complete the assignment during the lab period it is strongly recommended that you complete it on your own.
Getting Ready: Before going any further, you should:
PersonReader
class that is passed a File
object and instantiates scanner
.
What code did you add?
PersonReader
class to make sure your
changes are syntactically correct.
What exception did you have to catch or specify (i.e., re-throw)?
Integer.parseInt(java.lang.String)
method throws NumberFormatException
.
Why don't you have to catch or specify (i.e., re-throw) this
exception?
createPerson(String)
method in the
Person
class so that it throws a
NumberFormatException
if the age portion of the String
cannot be converted
to an int
.
What code did you add?
readPerson()
method in the
PersonReader
class so that it catches the
NumberFormatException
and creates a
fictitious person with default values for the
various attributes.
What code did you add?
createPerson(String)
method in the
Person
class so that it also throws a
NumberFormatException
if the area code,
exchange, or extension do not represent valid integers.
(Hint: You don't have to add a throw
statement.)
What code did you add?
NumericValueException
class
that only has a default constructor. The resulting Exception
object must have an appropriate description.
What code did you write?
createPerson(String)
method in the
Person
class so that it no longer throws
a NumberFormatException
if the age is not an int
.
Instead, it must now throw a NumericValueException
.
(Hint: You will need to catch the NumberFormatException
.)
What code did you add?
readPerson()
method in the
PersonReader
class so that it catches the
NumericValueException
and creates a
fictitious person with default values for the
various attributes.
What code did you add?
NumericValueException
class that is passed an
int
. The resulting Exception
object must have a description that includes the text
"Invalid numeric value: " and the parameter
value. (Note: You will use this constructor later.)
What code did you add?
createPerson(String)
method in the
Person
class so that it prints a message and then
re-throws the
NumberFormatException
if the age is not an
int
and throws a
NumericValueException
if the age is an int
and less than 18.
What code did you add?
readPerson()
method in the
PersonReader
class so that when it catches the
NumericValueException
it creates a
fictitious person named "Young Person" with default values for the
other attributes.
What code did you add?
NumericValueException
class that is passed a
Throwable
that is used as the
cause.
What code did you add?
createPerson(String)
method in the
Person
class so that it throws a
NumericValueException
that contains the
NumberFormatException
as the cause if the age is not
an int
.
What code did you add?
readPerson()
method in the
PersonReader
class so that when it catches a
NumericValueException
without a cause it creates a
fictitious person named "Ageless Person" with default values for the
other attributes. (Hint: Use the inherited
Throwable.getCause()
method.)
What code did you add?
Copyright 2016