/* TriangleDriver.java * Contains the main part of the program about triangles. * We create a triangle object based on the lengths of the sides, * then we classify the triangle. */ public class TriangleDriver { public static void main(String [] args) { // We could ask the user to enter 3 values for the lengths // of the sides, but we already know how to do this. // To simplify this example, I'll just hard-code some values. // Create a triangle given the lengths of 3 sides: Triangle t = new Triangle(65, 72, 97); // Now let's ask this triangle some questions. System.out.printf("Looking at triangle: %s\n", t.toString()); // First, quit the program if the lengths don't make sense. // The "return" statement gets us out of the current function. if (! t.isValid()) { System.out.printf("invalid values for triangle\n"); System.out.printf("make sure values are in ascending order\n"); return; } // Compare lengths of the sides. if (t.isEquilateral()) System.out.printf("equilateral\n"); else if (t.isIsosceles()) System.out.printf("isosceles\n"); else System.out.printf("scalene\n"); // Finally, say something about the angles. if (t.isRight()) System.out.printf("right\n"); else if (t.isObtuse()) System.out.printf("obtuse\n"); else System.out.printf("acute\n"); System.out.printf("The perimeter is %d.\n", t.findPerimeter()); } }