Question: Java In class, we discussed the GeoObject class. Design a class called Pentagon that extends the GroObject class. The Pentagon class should contain: 5 private

Java

In class, we discussed the GeoObject class. Design a class called Pentagon that extends the GroObject class. The Pentagon class should contain:

5 private double values for side1, side2, side3, side4, and side5.

a no-arg constructor that creates a default pentagon

a constructor that takes parameters that creates a pentagon with specified side lengths

accessors and mutators for all sides

a method named getArea() that returns the area of the pentagon (formula below)

a method named getPerimeter() that returns the perimeter of the pentagon

a toString() method that prints the following: "Pentgon: side1="+this.side1+" side2="+this.side2+" side3="+this.side3+" side4=+"this.side4+" side5="+this.side5;

Draw a UML diagram for the Pentagon class (submitted in a Word doc file) and implement the class (in Pentagon.java). Write a test program called lastname_lab2p1.java that asks the user for 5 sides of a Pentagon, a color, and a fill setting (true or false). The program should create a Pentagon instance with these sides and set the color and fill properties using the provided input. The program should display the area, perimeter, color, and fill setting.

GeoObject:

public abstract class GeoObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated;

/** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); }

/** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; }

/** Return color */ public String getColor() { return color; }

/** Set a new color */ public void setColor(String color) { this.color = color; }

/** Return filled. Since filled is boolean, * the get method is named isFilled */ public boolean isFilled() { return filled; }

/** Set a new filled */ public void setFilled(boolean filled) { this.filled = filled; }

/** Get dateCreated */ public java.util.Date getDateCreated() { return dateCreated; }

@Override public String toString() { return "created on " + dateCreated + " color: " + color + " and filled: " + filled; }

/** Abstract method getArea */ public abstract double getArea();

/** Abstract method getPerimeter */ public abstract double getPerimeter(); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!