Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. class Trapezoid extends Quadrilaterals {
  2. private static int numOfTrapezoids = 0;
  3. private double firstBase, secondBase, firstSideLength1, secondSideLength1, height2;
  4. private int serialNumber;
  5.  
  6. public Trapezoid() {
  7. firstBase = 1.0;
  8. secondBase = 1.0;
  9. firstSideLength1 = 1.0;
  10. secondSideLength1 = 1.0;
  11. height2 = 1.0;
  12. numOfTrapezoids++;
  13. serialNumber = numOfTrapezoids;
  14. }
  15.  
  16. public Trapezoid(double firstBase, double secondBase, double firstSideLength1, double secondSideLength1, double height2) {
  17. this.firstBase = firstBase;
  18. this.secondBase = secondBase;
  19. this.firstSideLength1 = firstSideLength1;
  20. this.secondSideLength1 = secondSideLength1;
  21. this.height2 = height2;
  22. }
  23.  
  24. public Trapezoid(boolean check) {
  25. if (check == true) {
  26. numOfTrapezoids++;
  27. serialNumber = numOfTrapezoids;
  28. }
  29. } //End of Trapezoid method
  30.  
  31. public double getFirstBase() {
  32. return firstBase;
  33. } //End of getFirstBase method
  34.  
  35. public double getSecondBase() {
  36. return secondBase;
  37. } //End of getSecondBase method
  38.  
  39. public double getFirstSideLength1() {
  40. return firstSideLength1;
  41. } //End of getFirstSideLength1 method
  42.  
  43. public double getSecondSideLength1() {
  44. return secondSideLength1;
  45. } //End of getSecondSideLength1 method
  46.  
  47. public double getHeight2() {
  48. return height2;
  49. } //End of getHeight2 method
  50.  
  51. public void setFirstBase(double firstBase) {
  52. this.firstBase = firstBase;
  53. } //End of setFirstBase method
  54.  
  55. public void setSecondBase(double secondBase) {
  56. this.secondBase = secondBase;
  57. } //End of setSecondBase method
  58.  
  59. public void setFirstSideLength1(double firstSideLength1) {
  60. this.firstSideLength1 = firstSideLength1;
  61. } //End of setFirstSideLength1 method
  62.  
  63. public void setSecondSideLength1(double secondSideLength1) {
  64. this.secondSideLength1 = secondSideLength1;
  65. } //End of setSecondSideLength method
  66.  
  67. public void setHeight2(double height2) {
  68. this.height2 = height2;
  69. } //End of setHeight2 method
  70.  
  71. public int getSerialNumber() {
  72. return serialNumber;
  73. }
  74.  
  75. public double findPerimeter() {
  76. return firstBase + secondBase + firstSideLength1 + secondSideLength1;
  77. } //End of findPerimeter method
  78.  
  79. public double findArea() {
  80. return (firstBase + secondBase)/2 * height2;
  81. } //End of findArea method
  82.  
  83. public static int getNumOfTrapezoids() {
  84. return numOfTrapezoids;
  85. } //End of getNumOfTrapezoids method
  86.  
  87. public String toString() {
  88. return ("[Trapezoid " + serialNumber + "]\nFirst Base: " + getFirstBase() + "\nSecond Base: " + getSecondBase() + "\nFirst Side Length: " + getFirstSideLength1() + "\nSecond Side Length: " + getSecondSideLength1() + "\nHeight: " + getHeight2() + "\nThe area is " + findArea() + "\nThe perimeter is " + findPerimeter() + "\n");
  89. } //End of toString method
  90.  
  91. public boolean equals(Object o) {
  92. if (o instanceof Trapezoid) {
  93. Trapezoid t = (Trapezoid)o;
  94. if (this.getSerialNumber() == t.getSerialNumber())
  95. return true;
  96. }
  97. return false;
  98. } //End of equals method
  99. } //End of class Trapezoid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement