19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

11.2 Superclasses and Subclasses 409<br />

GeometricObject<br />

-color: String<br />

-filled: boolean<br />

-dateCreated: java.util.Date<br />

+GeometricObject()<br />

+GeometricObject(color: String,<br />

filled: boolean)<br />

+getColor(): String<br />

+setColor(color: String): void<br />

+isFilled(): boolean<br />

+setFilled(filled: boolean): void<br />

+getDateCreated(): java.util.Date<br />

+<strong>to</strong>String(): String<br />

The color of the object (default: white).<br />

Indicates whether the object is filled with a color (default: false).<br />

The date when the object was created.<br />

Creates a GeometricObject.<br />

Creates a GeometricObject with the specified color and filled<br />

values.<br />

Returns the color.<br />

Sets a new color.<br />

Returns the filled property.<br />

Sets a new filled property.<br />

Returns the dateCreated.<br />

Returns a string representation of this object.<br />

-radius: double<br />

Circle<br />

+Circle()<br />

+Circle(radius: double)<br />

+Circle(radius: double, color: String,<br />

filled: boolean)<br />

+getRadius(): double<br />

+setRadius(radius: double): void<br />

+getArea(): double<br />

+getPerimeter(): double<br />

+getDiameter(): double<br />

+printCircle(): void<br />

-width: double<br />

-height: double<br />

Rectangle<br />

+Rectangle()<br />

+Rectangle(width: double, height: double)<br />

+Rectangle(width: double, height: double<br />

color: String, filled: boolean)<br />

+getWidth(): double<br />

+setWidth(width: double): void<br />

+getHeight(): double<br />

+setHeight(height: double): void<br />

+getArea(): double<br />

+getPerimeter(): double<br />

FIGURE 11.1<br />

The GeometricObject class is the superclass for Circle and Rectangle.<br />

SimpleGeometricObject, CircleFromSimpleGeometricObject, and<br />

RectangleFromSimpleGeometricObject in this chapter. For simplicity, we will<br />

still refer <strong>to</strong> them in the text as GeometricObject, Circle, and Rectangle<br />

classes. The best way <strong>to</strong> avoid naming conflicts is <strong>to</strong> place these classes in different<br />

packages. However, for simplicity and consistency, all classes in this book are placed in<br />

the default package.<br />

LISTING 11.1<br />

SimpleGeometricObject.java<br />

1 public class SimpleGeometricObject {<br />

2 private String color = "white";<br />

3 private boolean filled;<br />

4 private java.util.Date dateCreated;<br />

5<br />

6 /** Construct a default geometric object */<br />

7 public SimpleGeometricObject() {<br />

8 dateCreated = new java.util.Date();<br />

data fields<br />

construc<strong>to</strong>r<br />

date constructed

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!