Java Reference
In-Depth Information
the previous exercises). Include at least these methods: a method
set
to set the
hours, minutes, and seconds; a method
click()
, which increments the seconds
by
1
(and the minutes if the seconds becomes
0
, and the hours in the same man-
ner); and method
toString
. Method
toString
should give the value in the form
hours
:
minutes
:
seconds
.
E12.
Write a class
Point
, which represents an
(x, y)
point in the plane. Include
normal methods, like
toString
, as well as instance function
length(Point)
,
which yields the length from the point in which the function appears to its param-
eter. Now write a subclass
ThreeDPoint
, which represents a three-dimension-
al point in
(x, y, z)
space. Override method length appropriately. Is this an
appropriate way to write class
ThreeDPoint
, or should it stand alone and not be
a subclass of
Point
?
E13.
Section 4.6.2 discussed the design of a set of classes whose instances were
shapes drawn using a
Graphics g
. Design, implement, and test a similar set of
classes whose superclass is
Vehicle
, which is some vehicle that appears at some
(x,y)
position. Possibilities for vehicles are cars, trucks (with subtypes pickup,
flatbed, moving van, etc.), cycle (motorcycle, bicycle, unicycle), etc. This is a
completely open-ended problem: you choose the vehicles, what each vehicle
looks like, and the subclass hierarchy.
E14.
Study the subclass hierarchy in the
javax.swing
and
java.awt
packages
that includes class
JFrame
. Look at the superclasses of
JFrame
and get a basic
idea of what each one is for and what its methods are.
Search WWH ::
Custom Search