Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Trapezoid extends Quadrilaterals {
- private static int numOfTrapezoids = 0;
- private double firstBase, secondBase, firstSideLength1, secondSideLength1, height2;
- private int serialNumber;
- public Trapezoid() {
- firstBase = 1.0;
- secondBase = 1.0;
- firstSideLength1 = 1.0;
- secondSideLength1 = 1.0;
- height2 = 1.0;
- numOfTrapezoids++;
- serialNumber = numOfTrapezoids;
- }
- public Trapezoid(double firstBase, double secondBase, double firstSideLength1, double secondSideLength1, double height2) {
- this.firstBase = firstBase;
- this.secondBase = secondBase;
- this.firstSideLength1 = firstSideLength1;
- this.secondSideLength1 = secondSideLength1;
- this.height2 = height2;
- }
- public Trapezoid(boolean check) {
- if (check == true) {
- numOfTrapezoids++;
- serialNumber = numOfTrapezoids;
- }
- } //End of Trapezoid method
- public double getFirstBase() {
- return firstBase;
- } //End of getFirstBase method
- public double getSecondBase() {
- return secondBase;
- } //End of getSecondBase method
- public double getFirstSideLength1() {
- return firstSideLength1;
- } //End of getFirstSideLength1 method
- public double getSecondSideLength1() {
- return secondSideLength1;
- } //End of getSecondSideLength1 method
- public double getHeight2() {
- return height2;
- } //End of getHeight2 method
- public void setFirstBase(double firstBase) {
- this.firstBase = firstBase;
- } //End of setFirstBase method
- public void setSecondBase(double secondBase) {
- this.secondBase = secondBase;
- } //End of setSecondBase method
- public void setFirstSideLength1(double firstSideLength1) {
- this.firstSideLength1 = firstSideLength1;
- } //End of setFirstSideLength1 method
- public void setSecondSideLength1(double secondSideLength1) {
- this.secondSideLength1 = secondSideLength1;
- } //End of setSecondSideLength method
- public void setHeight2(double height2) {
- this.height2 = height2;
- } //End of setHeight2 method
- public int getSerialNumber() {
- return serialNumber;
- }
- public double findPerimeter() {
- return firstBase + secondBase + firstSideLength1 + secondSideLength1;
- } //End of findPerimeter method
- public double findArea() {
- return (firstBase + secondBase)/2 * height2;
- } //End of findArea method
- public static int getNumOfTrapezoids() {
- return numOfTrapezoids;
- } //End of getNumOfTrapezoids method
- public String toString() {
- 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");
- } //End of toString method
- public boolean equals(Object o) {
- if (o instanceof Trapezoid) {
- Trapezoid t = (Trapezoid)o;
- if (this.getSerialNumber() == t.getSerialNumber())
- return true;
- }
- return false;
- } //End of equals method
- } //End of class Trapezoid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement