Due Tuesday, November 28 at 1:59 PM
By the time you have completed this work, you should be able to:
try
, throw
, and throws
)catch
)lab21_handout.pdf
InvalidNumberException.java
NumberValidator.java
PositiveNumber.java
NonNegativeNumber.java
NumberValidatorMain.java
collaborators.txt
Write out the output of the different programs in the Lab 21 Handout. You can either turn this in at the beginning of class in the next session, or scan it / take a high-quality picture and submit it through Canvas.
Download all the provided .java
files under the Provided files listing above.
InvalidNumberException.java
You will need to define a custom class
.
The comments in InvalidNumberException.java
provide more details.
NumberValidator.java
You will need to define a custom abstract class
.
The comments in NumberValidator.java
provide more details.
PositiveNumber.java
You will need to define a custom class
.
The comments in PositiveNumber.java
provide more details.
NonNegativeNumber.java
You will need to define a custom class
.
The comments in NonNegativeNumber.java
provide more details.
NumberValidatorMain.java
Run the main
method in NumberValidatorMain.java
.
This code takes two command-line arguments:
If a number cannot be parsed, it will output an appropriate error message, depending on what was wrong.
For example, underneath the command-line arguments 2 3
this will produce the following output:
Parsed and valid: 2 Parsed and valid: 3
As another example, the following is the output for the command-line arguments foo -1
:
java.lang.NumberFormatException: For input string: "foo" Is negative: -1
As a third example, the following is the output for the command-line arguments 0 0
:
Not positive: 0 Parsed and valid: 0
Log into Canvas, and go to the COMP 110L class. Click “Assignments” on the left pane, then click “Lab 21”. From here, you can upload your code. Specifically, you must turn in the following four files:
InvalidNumberException.java
NumberValidator.java
PositiveNumber.java
NonNegativeNumber.java
If you want to perform a digital submission of your handout, you can scan it / take a high-quality picture, and submit it as a series of .jpg
files.
In addition, if you collaborated with anyone else, be sure to download collaborators.txt
and write the names of the people you collaborated with in the file, one per line.
Please submit this file along with the other files.
You can turn in the assignment multiple times, but only the last version you submitted will be graded.