Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rectangle {
- private double length, width;
- Rectangle() {
- this.length = 1;
- this.width = 1;
- }
- Rectangle(int width, int length) {
- if (isMeasureValid(width)) {
- this.width = width;
- }
- else {
- this.width = 1;
- }
- if (isMeasureValid(length)) {
- this.length = length;
- }
- else {
- this.length = 1;
- }
- }
- public double getPerimeter() {
- return ( (width*2) + (length*2) );
- }
- public double getArea() {
- return ( width * length );
- }
- public void setWidth(double width) {
- if (isMeasureValid(width)) {
- this.width = width;
- }
- }
- public void setLength(double length) {
- if (isMeasureValid(length)) {
- this.length = length;
- }
- }
- private boolean isMeasureValid(double length) {
- return length > 0 && length <= 20;
- }
- public double getWidth() {
- return this.width;
- }
- public double getLength() {
- return this.length;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement