Create a class Rectangle with attributes length and width, each of which default
ID: 3634378 • Letter: C
Question
Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the rectangle's perimeter and area. It has set and get methods for both length and width. The set methods should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. Write a program to test class Rectangle.
Program should be written in Java .
I need some with this problem so urgently----test is due tomorrow and will be similar to the above question. I cannot afford to fail the test.
Explanation / Answer
Dear, Here is the code class Rectangle { private double length; private double width; /** The setLength method stores a value in the length field. @param len The value to store in length. */ public void setLength(double len) { if(len>0&&len0&&wRelated 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.