Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COMPLETE JAVA CODE AND SHOW OUTPUT public class Assignment1 { public static void main(String[] args) { Rectangle rectangle = new Rectangle (1.0, 1.5); rectangle.setColor(yellow); rectangle.setFilled(true);

image text in transcribed

COMPLETE JAVA CODE AND SHOW OUTPUT

public class Assignment1 {

public static void main(String[] args) {

Rectangle rectangle = new Rectangle (1.0, 1.5);

rectangle.setColor("yellow");

rectangle.setFilled(true);

System.out.println(rectangle);

System.out.println("The area is " + rectangle.getArea());

System.out.println("The perimeter is "

+ rectangle.getPerimeter());

System.out.println(rectangle);

}

}

public abstract class GeometricObject {

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();

}

public class Rectangle extends GeometricObject {

// Implement it

}

Question 3: [Programming] Design a class named Rectangle that extends Geometricobject. The class contains: - Two double data fields named width, and length with default values 1.0 to denote two sides of the rectangle. - A constructor that creates a rectangle with the specified width, and length. - The get and set methods for all two data fields. - A method named getarea() that returns the area of this rectangle. - A method named getperimeter() that returns the perimeter of this rectangle. - A method named tostring() that returns a string description for the rectangle, as follows return"Rectangle:Width="+width+"length="+length; - Your code must be fully documented. This includes using Javadoc comments. - Use the following code as a startup for your solution. You only need to implement the Rectangle class

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

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions