Professional Documents
Culture Documents
Cs Homework 04-18-17
Cs Homework 04-18-17
Cs Homework 04-18-17
Pg. 249 Ex 10.1.1 Pg. 254 10.1.2 Pg. 254 10.1.3 Pg. 256 10.1.4 Pg. 264 10.5.1
10.1.1 - define an interface called visualinterface that contains methods show, hide, and
setcolor
10.1.2 - use the definition of the resizable interface to complete the exercises below and on the
following pages.
A. Write the class header for a class called square that implements the resizable interface
B. What methods must the square class define to legally implement the resizable
interface?
C. Finish the square class. The constructor should take three parameters, a location, a
double for size, and the canvas. It should draw a filled rectangle at the location with each
side having length specified by the size of the parameter. The resize method should set
the height and width of the filledrect to the size determined by the double parameter. The
contains method should return true if the filledrect contains the location that was passed
as a parameter. Otherwise it should return false.
Filledrect square;
square.setwidth(size);
square.setheight(size);
10.1.3 - design a class called circle that resembles square except that the instance variable for
the circle class is a filledoval
Filledoval circle;
}
Public void resize ( double size)
circle.setwidth(size);
circle.setheight(size);
10.1.4 - using the resizable interface from exercise 10.1.2 and the classes square and circle
write a program called shapesizer. When the mouse is pressed, the program should randomly
decide to draw either a circle or a square at the point of press. When the shape is drawn it
should have size 100. When the mouse is released the shape should shrink to half its original
size.
If (value() == 1)
Else
}
public int value()
return generator.nextValue();
If (shape.contains (point);
Shape.resize (50);
10.5.1 - given the alphabet interface above and the two classes below that implement the
alphabet interface which statements are legal? Assume that each class has a constructor that
takes no parameters.