Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MuradHomeWork;
- public class Rectangle {
- public double length;
- public double width;
- static double totalArea=0;
- public Rectangle(double length, double width) {
- this.length = length;
- this.width = width;
- totalArea += this.area();
- }
- public Rectangle(Rectangle other) {
- this.length = other.getLength();
- this.width = other.getWidth();
- totalArea += this.area();
- }
- public double area() {
- return this.length*this.width;
- }
- public Rectangle inflate(double factor) {
- return new Rectangle(this.length*factor, this.width*factor);
- }
- public double greaterArea(Rectangle other) {
- if(this.length*this.width > other.getLength()*other.getWidth())
- return this.length*this.width;
- else
- return other.getLength()*other.getWidth();
- }
- public String toString() {
- return "[" + this.length + " x " + this.width + "]";
- }
- public static double totalArea() {
- return totalArea;
- }
- public double getLength() {
- return length;
- }
- public void setLength(double length) {
- this.length = length;
- }
- public double getWidth() {
- return width;
- }
- public void setWidth(double width) {
- this.width = width;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement