Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java NetBeans Please, Include comments that explain functions. Problem 1: In class, we discussed the GeoObject class. Design a class called Pentagon that extends the

Java

NetBeans

Please, Include comments that explain functions.

Problem 1:

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions