import java.awt.geom.Point2D; import java.util.Scanner; /** * Test program for CS 160, Lab 4. * * @author John Paxton * @version September 30, 2008 */ public class UserInterface { public static void main (String [] args) { Point2D.Double point1; // first point of triangle Point2D.Double point2; // second point of triangle Point2D.Double point3; // third point of triangle Triangle triangle; // triangle System.out.println("CS 160, Lab 4"); System.out.println("-------------\n"); point1 = getPoint(); point2 = getPoint(); point3 = getPoint(); triangle = new Triangle(point1, point2, point3); System.out.println("The perimeter of the triangle = " + triangle.getPerimeter()); System.out.println("The area of the triangle = " + triangle.getArea()); } /** * Prompts the user for the x,y coordinates of a point. * @return Point2D.Double, a point on a triangle */ private static Point2D.Double getPoint() { double x; // x coordinate of point double y; // y coordinate of point Point2D.Double point; // entire point Scanner in; // user input source in = new Scanner (System.in); System.out.println("Triangle Point Input"); System.out.print("Enter x: "); x = in.nextDouble(); System.out.print("Enter y: "); y = in.nextDouble(); System.out.println("---------------"); point = new Point2D.Double(x,y); return point; } }