This is for an intro to Java class. The simpler the solution, the better. I\'m s
ID: 3634414 • Letter: T
Question
This is for an intro to Java class. The simpler the solution, the better. I'm supposed to be studying this for an upcoming test. The problem says:Design a class named Rectangle to represent a rectangle. The class contains:
-two double data fields named width and height that specify the width and the height of the rectangle. The default values are 1 for both.
-a no-arg constructor that creates a default rectangle.
-a constructor that creates a rectangle with the specified width and height.
-a method named getArea() that returns the area of the rectangle.
-a method named getPerimeter() that returns the peremiter.
it should also display the width, height,area, and perimeter of the rectangle in this order.
I don't even know where to start with this.
Explanation / Answer
public class rectangle{ /********************** *Variable Declaration *********************/ double width; double Height; static int noofobjects; /************************** *DEFAULT CONSTRUCTOR **************************/ public rectangle(){ setWidth(0); // calling setwidth setHeight(0); // calling setheight noofobjects++; } /***************************** *CUSTOM CONSTRUCTOR ****************************/ public rectangle(double wid, double hi){ setWidth(wid); // calling setwidth setHeight(hi); // calling setheight noofobjects++; } /**************************** *Getters And Setters ****************************/ public void setWidth(double wi) { if(wiRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.