Java Reference
In-Depth Information
3. Your try block is going to have two catch blocks, one for an Array-
IndexOutOfBoundsException and one for a NumberFormatException.
4. If an ArrayIndexOutOfBoundsException occurs, the user has not
input two command-line arguments. Inform the user of this, print
the stack trace, and have main() end using a return statement.
5. If a NumberFormatException occurs, the user has input invalid
command-line arguments. Inform the user that the program expects
two ints; then print the stack trace and have main() end.
6. If no exception occurs, print out the two ints and also their product.
7.
Save, compile, and run the Mulitply program several times by using
the following command lines:
java Multiply 10 5
java Multiply 10
java Multiply 7 hello
Lab 11.2: Exceptions and Polymorphism
In this lab, you will replace the two catch blocks in the Multiply program
of Lab 11.1 with a single catch block.
1. Start off by making a copy of the Multiply.java file, renaming
it MultiplyLazy.java. You will also need to rename the class
MultiplyJava.
2. Remove the two catch blocks and replace them with a single catch
block that catches RuntimeException.
3. Within the catch block, print out a message that an error has
occurred and also print the stack trace.
4. The remainder of the MultiplyLazy class can remain the same. Save,
compile, and run the program three times, using the following com-
mand lines:
java MultiplyLazy 10 5
java MultiplyLazy 10
java MultiplyLazy 7 hello
Lab 11.3: Checked Exceptions
In Lab 10.1, you wrote a program that instantiated a FootballGame object
and simulated a football game, having the home and visiting teams score
Search WWH ::




Custom Search