Вы находитесь на странице: 1из 2

Computer Programming

05/19/2014
Lab 13
Problem 1: Download
Lab13-Problem1.zip
from the course website. Unzip the file and
you will find java files
GeometricObject.java
,
Circle.java, Rectangle.java
(Note: Onl GeometricObject.java
is needed for this problem. The rest will be used
in the homework.
!
. Design an interface named
Colorable
with a
voi"
method named
#o$%oColor(!
. very class of a colorable object must implement the !olorable interface.
Design a class named
&'(are
that e"tends
GeometricObject
and implements
Colorable
. #mplement
#o$%oColor
to display the message:
Color all )o(r *i"e*
. $
sample client code and sample run look like:
p(blic *tatic voi" main(&tring+, arg*! -
&'(are *'(are . ne$ &'(are(/!0
*'(are.#o$%oColor(!0
1
Color all four sides
Problem 2: %iven an abstract class named
Grap#ic*Object
and two interfaces named
Object/2
and
Object32
as follows:
p(blic ab*tract cla** Grap#ic*Object -
p(blic ab*tract &tring getName(!0
1
inter)ace Object/2 -
p(blic ab*tract "o(ble get3rea(!0
1
inter)ace Object32 -
p(blic ab*tract "o(ble get4ol(me(!0
1
Design a subclass of
Grap#ic*Object
named
Rectangle
that implements the
Object/2

interface and another subclass of
Grap#ic*Object
named
5o6
that implements the
Object32
interface. The
Rectangle
class has two data fields named
$i"t#
and
#eig#t
,
while the
5o6
class has three data fields named
lengt#
,
$i"t#
and
#eig#t
. !omplete the
following test program:
&
Computer Programming
05/19/2014
p(blic cla** Lab13Problem/ -
p(blic *tatic voi" main(&tring+, arg*! -
Grap#ic*Object+, go . ne$ Grap#ic*Object+3,0
go+7, . ne$ Rectangle(1,/!0
go+1, . ne$ 5o6(/,3,8!0
go+/, . ne$ Rectangle(3,8!0
)or (int i.70 i9go.lengt#0 i::! -
;;to be complete"
1
1
1
'o the following output is obtained:
Name: Rectangle; Area = 2.0
Name: Box; Volume = 24.0
Name: Rectangle; Area = 12.0
(

Вам также может понравиться