Java Reference
In-Depth Information
public
MyException(String msg)
{
super
(msg);
System.out.println("Attention required!");
}
}
What output will be produced if the exception is thrown with the default
constructor? What output will be produced if the exception is thrown by the
constructor with parameter with the actual parameter
"May Day, May Day"
?
17.
If a method throws an exception, how does it specify that exception?
18.
Name three exception handling techniques.
19.
What are the three different ways you can implement an interface?
1.
Write a program that prompts the user to enter the length in feet and inches
and outputs the equivalent length in inches and in centimeters. If the user
enters a negative number or a nondigit number, throw and handle an
appropriate exception and prompt the user to enter another set of numbers.
2.
Redo the Text Processing programming example in Chapter 9 so that if the array
index goes out of bounds when the program accesses the array
letterCount
,
it throws and handles the
ArrayIndexOutOfBoundsException
.
3.
Write a program that prompts the user to enter time in 12-hour notation. The
program then outputs the time in 24-hour notation. Your program must
contain three exception
class
es:
InvalidHrExcep
,
InvalidMinExcep
,
and
InvalidSecExcep
. If the user enters an invalid value for hours, then
the program should throw and catch an
InvalidHr
object. Similar conven-
tions for the values of minutes and seconds.
4.
Write a program that prompts the user to enter a person's date of birth in
numeric form such as 8-27-1980. The program then outputs the date of birth in
the form: August 27, 1980. Your program must contain at least two exception
class
es:
InvalidDayExcep
and
InvalidMonthExcep
. If the user enters an
invalid value for day, then the program should throw and catch an
InvaliDayExcep
object. Similar conventions for the values of month and
year. (Note that your program must handle a leap year.)
5.
Redo Programming Exercise 7 of Chapter 8 so that your program handles
exceptions such as division by zero.
6.
Extend the Calculator programming example of this chapter by adding three
buttons with the labels
M
,
R
, and
E
as follows: If the user clicks the button
M
,
the number currently in the
displayText
field is stored in the variable, say,
memory
; if the user clicks the button
R
, the number stored in memory is
displayed and also becomes the first number (so that another number can be
1
1
Search WWH ::
Custom Search