Advertisement
_MuradPro_

Rectangle

Sep 10th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package MuradHomeWork;
  2.  
  3. public class Rectangle {
  4. public double length;
  5. public double width;
  6. static double totalArea=0;
  7.  
  8. public Rectangle(double length, double width) {
  9.     this.length = length;
  10.     this.width = width;
  11.     totalArea += this.area();
  12. }
  13.  
  14. public Rectangle(Rectangle other) {
  15.     this.length = other.getLength();
  16.     this.width = other.getWidth();
  17.     totalArea += this.area();
  18. }
  19.  
  20. public double area() {
  21.     return this.length*this.width;
  22. }
  23.  
  24. public Rectangle inflate(double factor) {
  25.     return new Rectangle(this.length*factor, this.width*factor);
  26. }
  27.  
  28. public double greaterArea(Rectangle other) {
  29.     if(this.length*this.width > other.getLength()*other.getWidth())
  30.         return this.length*this.width;
  31.     else
  32.         return other.getLength()*other.getWidth();
  33. }
  34.  
  35. public String toString() {
  36.     return "[" + this.length + " x " + this.width + "]";
  37. }
  38.  
  39. public static double totalArea() {
  40.     return totalArea;
  41. }
  42.  
  43. public double getLength() {
  44.     return length;
  45. }
  46.  
  47. public void setLength(double length) {
  48.     this.length = length;
  49. }
  50.  
  51. public double getWidth() {
  52.     return width;
  53. }
  54.  
  55. public void setWidth(double width) {
  56.     this.width = width;
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement