Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The outline of the class is given as follows: public classMyRectangle{ private d

ID: 3618290 • Letter: T

Question

The outline of the class is given as follows:

public classMyRectangle{

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

publicMyRectangle(){ }

publicMyRectangle(double widthParam, double heightParam, StringcolorParam){ }

public doublegetWidth(){ }

public voidsetWidth(double widthParam){ }

public doublegetHeight(){ }

public voidsetHeight(double heightParam){ }

public StringgetColor(){ }  

public staticvoid setColor(String colorParam){ }

public doublefindArea(){ }

}

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

Explanation / Answer

publicclass MyRectangle { privatedouble width = 1.0; privatedouble height = 1.0; privatestatic String color ="white"; publicMyRectangle() { width = 1.0; height = 1.0; } publicMyRectangle(double widthParam,double heightParam, String colorParam) { setWidth(widthParam); setHeight(heightParam); setColor(colorParam); } publicdouble getWidth() { return width; } publicvoid setWidth(double widthParam) { width = widthParam; } publicdouble getHeight() { return height; } publicvoid setHeight(double heightParam) { height = heightParam; } publicString getColor() { return color; } publicstatic void setColor(StringcolorParam) { color = colorParam; } publicdouble findArea() { return getWidth()*getHeight(); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote