Java Reference
In-Depth Information
4. Modify the logging package so that Logger 's connect() method
throws CannotConnectException when it cannot connect to its log-
ging destination, and the other two methods each throw NotConnec-
tedException when connect() wasnotcalledorwhenitthrew Can-
notConnectException . Modify TestLogger to respond appropri-
atelytothrown CannotConnectException and NotConnectedEx-
ception objects.
5. ContinuingfromExercise3,useanassertiontoverifytheclassinvariantthat
the transformation matrix is initialized to the identity matrix before G2D 's
constructor ends.
6. Declare a ToDo marker annotation type that annotates only type elements,
and that also uses the default retention policy.
7. Rewrite the StubFinder application to work with Listing 3-43 's Stub
annotation type (with appropriate @Target and @Retention annota-
tions) and Listing 3-44 ' s Deck class.
8. Implementa Stack<E> generictypeinamannerthatissimilarto Listing
3-52 ' s Queue class. Stack must declare push() , pop() , and
isEmpty() methods(itcouldalsodeclarean isFull() methodbutthat
method is not necessary in this exercise), push() must throw a Stack-
FullException instancewhenthestackisfull,and pop() mustthrow
a StackEmptyException instancewhenthestackisempty.(Youmust
create your own StackFullException and StackEmptyExcep-
tion helperclassesbecausetheyarenotprovidedforyouinJava'sstandard
classlibrary.)Declareasimilar main() method,andinserttwoassertions
9. Declare a Compass enum with NORTH , SOUTH , EAST , and WEST mem-
bers. Declare a UseCompass class whose main() method randomly se-
lects one of these constants and then switches on that constant. Each of
the switch statement's cases should output a message such as heading
north .
Java supports advanced language features related to nested types, packages, static im-
ports, exceptions, assertions, annotations, generics, and enums.
Search WWH ::

Custom Search