/*********************************************************************/
/* Author: B. Alex Bridges                                           */
/* File: Geom.java                                                   */
/* Class: CPSC-101 Lab Section 3                                     */
/* Project: Lab 3 - Geometry                                         */
/* Purpose: 1. Read in and echo 3 points [(x,y) coordinates]         */
/*          2. Determine and echo the distances between each point   */
/*          3. Determine and echo their enclosed triangular area     */
/*          4. Determine and echo the slopes between each point      */
/*********************************************************************/

/* IMPORTS */
import java.io.*;


/*********************************************************************/
/* GEOM CLASS                                                        */
/*********************************************************************/
class Geom
{
	/*********************************************************************/
	/* MAIN METHOD                                                       */
	/*********************************************************************/
	public static void main (String [ ] args) throws IOException
	{
	
		/* LOCAL VARIABLES */
		double dbl_x1=0.0, dbl_y1=0.0, dbl_x2=0.0, dbl_y2=0.0, dbl_x3=0.0, dbl_y3=0.0; /* 3 PAIRS OF POINTS */
		double dbl_Dist1to2=0.0, dbl_Dist2to3=0.0, dbl_Dist3to1=0.0; /* DISTANCES BETWEEN EACH POINT */
		double dbl_s=0.0, dbl_Area=0.0; /* PART OF HERON'S FORMULA */
		double dbl_Slp1to2=0.0, dbl_Slp2to3=0.0, dbl_Slp3to1=0.0; /* SLOPES BETWEEN EACH POINT */
		
		/* STANDARD TEXT INPUT STREAM SETUP */
		BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
		
		/* HEADER */
		System.out.println ("B. Alex Bridges");
		System.out.println ("CPSC-101, Winter 1998");
		System.out.println ("The Geometry Program");
		System.out.println (" ");
		
		/* INPUT */
		// x1
		System.out.print ("Please enter 1st x coordinate: ");
		System.out.flush (); /* FORCES PROMPT */
		dbl_x1 = ((Double.valueOf (stdin.readLine ())).doubleValue ()); /* Strings => Doubles => doubles */
		// y1
		System.out.print ("Please enter 1st y coordinate: ");
		System.out.flush (); /* FORCES PROMPT */
		dbl_y1 = ((Double.valueOf (stdin.readLine ())).doubleValue ()); /* Strings => Doubles => doubles */
		// x2
		System.out.print ("Please enter 2nd x coordinate: ");
		System.out.flush (); /* FORCES PROMPT */
		dbl_x2 = ((Double.valueOf (stdin.readLine ())).doubleValue ()); /* Strings => Doubles => doubles */
		// y2
		System.out.print ("Please enter 2nd y coordinate: ");
		System.out.flush (); /* FORCES PROMPT */
		dbl_y2 = ((Double.valueOf (stdin.readLine ())).doubleValue ()); /* Strings => Doubles => doubles */
		// x3
		System.out.print ("Please enter 3rd x coordinate: ");
		System.out.flush (); /* FORCES PROMPT */
		dbl_x3 = ((Double.valueOf (stdin.readLine ())).doubleValue ()); /* Strings => Doubles => doubles */
		// y3
		System.out.print ("Please enter 3rd y coordinate: ");
		System.out.flush (); /* FORCES PROMPT */
		dbl_y3 = ((Double.valueOf (stdin.readLine ())).doubleValue ()); /* Strings => Doubles => doubles */
		System.out.println (""); /* BLANK LINE */
		
		/* ECHO 3 POINTS */
		System.out.println ("The points entered were: ");
		System.out.println (" 1. ("+dbl_x1+","+dbl_y1+")");
		System.out.println (" 2. ("+dbl_x2+","+dbl_y2+")");
		System.out.println (" 3. ("+dbl_x3+","+dbl_y3+")");
		System.out.println (""); /* BLANK LINE */
		
		/* DETERMINE AND ECHO THE DISTANCES BETWEEN EACH POINT */
		System.out.println ("The distances between each point are: ");
		// (x1,y1) to (x2,y2)
		System.out.print (" => Point 1 to Point 2 = ");
		dbl_Dist1to2 = (Math.sqrt ((Math.pow ((dbl_x2 - dbl_x1),2.0)) + (Math.pow ((dbl_y2 - dbl_y1),2.0))));
		System.out.println (dbl_Dist1to2);
		// (x2,y2) to (x3,y3)
		System.out.print (" => Point 2 to Point 3 = ");
		dbl_Dist2to3 = (Math.sqrt ((Math.pow ((dbl_x3 - dbl_x2),2.0)) + (Math.pow ((dbl_y3 - dbl_y2),2.0))));
		System.out.println (dbl_Dist2to3);
		// (x3,y3) to (x1,y1)
		System.out.print (" => Point 3 to Point 1 = ");
		dbl_Dist3to1 = (Math.sqrt ((Math.pow ((dbl_x1 - dbl_x3),2.0)) + (Math.pow ((dbl_y1 - dbl_y3),2.0))));
		System.out.println (dbl_Dist3to1);
		System.out.println (""); /* BLANK LINE */
		
		/* DETERMINE AND ECHO THEIR ENCLOSED TRIANGULAR AREA */
		System.out.println ("Their enclosed triangular area is:");
		// HERON'S FORMULA
		dbl_s = (0.5 * (dbl_Dist1to2 + dbl_Dist2to3 + dbl_Dist3to1));
		dbl_Area = (Math.sqrt (dbl_s * (dbl_s - dbl_Dist1to2) * (dbl_s - dbl_Dist2to3) * (dbl_s - dbl_Dist3to1)));
		System.out.println (" => "+dbl_Area);
		System.out.println (""); /* BLANK LINE */
		
		/* DETERMINE AND ECHO THE SLOPES BETWEEN EACH POINT */
		System.out.println ("The slopes between each point are: ");
		// (x1,y1) to (x2,y2)
		System.out.print (" => Point 1 to Point 2 = ");
		dbl_Slp1to2 = ((dbl_y2 - dbl_y1) / (dbl_x2 - dbl_x1));
		System.out.println (dbl_Slp1to2);
		// (x2,y2) to (x3,y3)
		System.out.print (" => Point 2 to Point 3 = ");
		dbl_Slp2to3 = ((dbl_y3 - dbl_y2) / (dbl_x3 - dbl_x2));
		System.out.println (dbl_Slp2to3);
		// (x3,y3) to (x1,y1)
		System.out.print (" => Point 3 to Point 1 = ");
		dbl_Slp3to1 = ((dbl_y1 - dbl_y3) / (dbl_x1 - dbl_x3));
		System.out.println (dbl_Slp3to1);
		System.out.println (""); /* BLANK LINE */	
	} //method main
} //class Geom
