Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class named MyRectangle to represent rectangles. The required data fields are width, height, and color. Use double data type for width and height,

Create a class named MyRectangle to represent rectangles. The required data fields are width, height, and color. Use double data type for width and height, and a String for color. Suppose that all rectangles are the same color. Use a static variable for color. You will need to provide the accessor methods for the properties and a method findArea() for computing the area of the rectangle.

The outline of the class is given as follows:

public class MyRectangle{

private double width = 1.0; private double height = 1.0; private static String color = "white";

public MyRectangle(){ }

public MyRectangle(double widthParam, double heightParam, String colorParam){ }

public double getWidth(){ }

public void setWidth(double widthParam){ }

public double getHeight(){ }

public void setHeight(double heightParam){ }

public String getColor(){ }

public static void setColor(String colorParam){ }

public double findArea(){ }

}

Write a program to test your class MyRectangle. In the client program, create two MyRectangle objects. Assign a width and height to each of the two objects. Assign the first object the color red, and the second, yellow. Display all properties of both objects including their area.

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

Assessment of skills and interests.

Answered: 1 week ago

Question

Psychological, financial, and career counseling.

Answered: 1 week ago