Problem

For the GeometricObject and Circle classes in Listings 1 and 2, answer the following quest...

For the GeometricObject and Circle classes in Listings 1 and 2, answer the following questions:

a. Assume are circle and object created as follows:

Circle circle = new Circle(1);

GeometricObject object = new GeometricObject();

Are the following Boolean expressions true or false?

(circle instanceof GeometricObject)

(object instanceof GeometricObject)

(circle instanceof Circle)

(object instanceof Circle)


b. Can the following statements be compiled?

Circle circle = new Circle(5);

GeometricObject object = circle;


c. Can the following statements be compiled?

GeometricObject object = new GeometricObject();

Circle circle = (Circle)object;

LISTING 1 SimpleGeometricObject.java

1 public class SimpleGeometricObject {

2 private String color = "white";

3 private boolean filled;

4 private java.util.Date dateCreated;

5

6 /** Construct a default geometric object */

7 public SimpleGeometricObject() {

8 dateCreated = new java.util.Date();

9 }

10

11 /** Construct a geometric object with the specified color

12 * and filled value */

13 public SimpleGeometricObject(String color, boolean filled) {

14 dateCreated = new java.util.Date();

15 this.color = color;

16 this.filled = filled;

17 }

18

19 /** Return color */

20 public String getColor() {

21 return color;

22 }

23

24 /** Set a new color */

25 public void setColor(String color) {

26 this.color = color;

27 }

28

29 /** Return filled. Since filled is boolean,

30 its getter method is named isFilled */

31 public boolean isFilled() {

32 return filled;

33 }

34

35 /** Set a new filled */

36 public void setFilled(boolean filled) {

37 this.filled = filled;

38 }

39

40 /** Get dateCreated */

41 public java.util.Date getDateCreated() {

42 return dateCreated;

43 }

44

45 /** Return a string representation of this object */

46 public String toString() {

47 return "created on " + dateCreated + "\ncolor: " + color +

48 " and filled: " + filled;

49 }

50 }

Listing 2 CircleFromSimpleGeometricObject.java

1 public class CircleFromSimpleGeometricObject

2 extends SimpleGeometricObject {

3 private double radius;

4

5 public CircleFromSimpleGeometricObject() {

6 }

7

8 public CircleFromSimpleGeometricObject(double radius) {

9 this.radius = radius;

10 }

11

12 public CircleFromSimpleGeometricObject(double radius,

13 String color, boolean filled) {

14 this.radius = radius;

15 setColor(color);

16 setFilled(filled);

17 }

18

19 /** Return radius */

20 public double getRadius() {

21 return radius;

22 }

23

24 /** Set a new radius */

25 public void setRadius(double radius) {

26 this.radius = radius;

27 }

28

29 /** Return area */

30 public double getArea() {

31 return radius * radius * Math.PI;

32 }

33

34 /** Return diameter */

35 public double getDiameter() {

36 return 2 * radius;

37 }

38

39 /** Return perimeter */

40 public double getPerimeter() {

41 return 2 * radius * Math.PI;

42 }

43

44 /** Print the circle info */

45 public void printCircle() {

46 System.out.println("The circle is created " + getDateCreated() +

47 " and the radius is " + radius);

48 }

49 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT