Untitled

mail@pastecode.io avatar
unknown
java
a year ago
3.1 kB
6
Indexable
Never
// 
// Decompiled by Procyon v0.5.36
// 

package trianglepackage;

public class Triangle
{
    private int side1;
    private int side2;
    private int side3;
    private static final String P_EQUILATERAL = "equilateral";
    private static final String P_ISOSCELES = "isossceles";
    private static final String P_RIGHTANGLED = "right-angled";
    private static final String P_SCALENE = "scalene";
    private static final String P_IMPOSSIBLE = "impossible";
    
    public Triangle(final int s1, final int s2, final int s3) {
        this.side1 = s1;
        this.side2 = s2;
        this.side3 = s3;
    }
    
    public Triangle setSideLengths(final int s1, final int s2, final int s3) {
        this.side1 = s1;
        this.side2 = s2;
        this.side3 = s3;
        return this;
    }
    
    public String getSideLengths() {
        return String.valueOf(this.side1) + "," + this.side2 + "," + this.side3;
    }
    
    public int getPerimeter() {
        return this.side1 + this.side2 + this.side3;
    }
    
    public double getArea() {
        if (!this.isImpossible()) {
            return Math.sqrt(this.getPerimeter() / 2 * (this.getPerimeter() / 2 - this.side1) * (this.getPerimeter() / 2 - this.side2) * (this.getPerimeter() / 2 - this.side3));
        }
        return -1.0;
    }
    
    public String classify() {
        if (this.isImpossible()) {
            return "impossible";
        }
        if (this.side1 == this.side2) {
            if (this.side2 == this.side3) {
                return "equilateral";
            }
            return "isossceles";
        }
        else {
            if (this.isRightAngled()) {
                return "right-angled";
            }
            return "scalene";
        }
    }
    
    public boolean isIsosceles() {
        return this.side1 == this.side2 || this.side2 == this.side3 || this.side1 == this.side3;
    }
    
    public boolean isEquilateral() {
        return this.side1 == this.side3;
    }
    
    public boolean isRightAngled() {
        final int[] sides = { this.side1, this.side2, this.side3 };
        return sides[2] == Math.sqrt((double)(sides[0] * (long)sides[0] + sides[1] * (long)sides[1]));
    }
    
    public boolean isScalene() {
        return this.side1 != this.side2 && this.side1 != this.side3 && this.side2 != this.side3;
    }
    
    public boolean isImpossible() {
        return this.side1 <= 0 || this.side2 <= 0 || this.side3 <= 0;
    }
    
    public static void main(final String[] args) {
        Triangle triangle = null;
        try {
            triangle = new Triangle(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]));
        }
        catch (Exception e) {
            System.out.println("Usage: java Quadrangle <side1:int> <side2:int> <side3:int>");
            return;
        }
        System.out.println("Type: " + triangle.classify());
        System.out.println("Triangle sides: " + triangle.getSideLengths());
        System.out.println("Area: " + triangle.getArea());
        System.out.println("Perimeter: " + triangle.getPerimeter());
    }
}