/* Chris Poon
	Burnett Honors College Summer Institute

	Intermediate Homework #1 Solution  - Points

	Note that to adhere to true OOP, I have in fact created two classes:
	The required Point class and a HW1 class that represents our homework.
	Thus, HW1 is the actual public class that contains a main and "executes"
	the program.
	Please be sure to read the comments in the HW1 class.

	Of course, such a tester class was not required, but I thought it would
	help illuminate what true OOP aspires to.  So you could easily
	have done all the things HW1 does in a main in class Point.

*/

import java.io.*;
import java.lang.Math;

class Point
{
	int x,y;		//represents the actual coordinates of this Point object.

	public Point(){
		//Default constructor -sets Point to "origin"
		x=0; y=0;
	}
	public Point(int a, int b){
		//Constructor to set coordinates to parameters.
		x=a; y=b;
	}
	public double distanceTo(Point other){
		//Public method to return the distance as a double between _this_ 
		//point and parameter _other_

		return Math.sqrt( (x-other.x)*(x-other.x) + (y-other.y)*(y-other.y) );
	}
	public String directionTo(Point other){
		//Public method to return a string representing the direction from
		// _this_ Point and the parameter _other_

		String direction="";
		if (other.y>y) direction="N";			//if-else since only North XOR South
		else if (other.y<y) direction="S";

		if (other.x>x) direction+="E";			//if-else since only East XOR West
		else if (other.x<x) direction+="W";

		return direction;
	}
	public String toString(){
		//public method to return a String object representing _this_ Point.
		//  provided so there is an easy and appropriate way to output the object

		return ("(" + x + "," + y + ")");
	}
}

public class HW1{
	//This object is the basis for executing the program in the spirit of true OOP.
	//That is, main should be clear, and in fact, HW1 is the class/object
	//  that represents our homework.
	//This also facilitates "helper" functions such as menu() that would be
	//  un-OOP like if in the Point class itself.

	Point pt1;			//the points the user will be inputting/comparing.
	Point pt2;
	
	public HW1() throws IOException{
		// This "Constructor" could be considered the "real" main, since 
		// when we create the Homework, we want it to "run" as per the doc.

		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		String aline;
		int choice=-1;

		pt1=new Point();	//initialize the points to be at the origin
		pt2=new Point();

		while (choice!=4){	//the loop for menu and executing user choices.
			menu();
			aline=input.readLine();
			choice=Integer.parseInt(aline);

			switch (choice){
				case 1:{
					pt1=inputPoint();
					break;
				}
				case 2:{
					pt2=inputPoint();
					break;
				}
				case 3:{
					calculate();
					break;
				}
				case 4:{ break;}
				default: {
					System.out.println("Invalid Choice, try again");
				}
			}
		}
	}

	void menu(){
		//a private HW1 method that displays the menu

		System.out.println("");
		System.out.println("1. Set Point 1");
		System.out.println("2. Set Point 2");
		System.out.println("3. Compute Distance & Direction");
		System.out.println("4. Quit");
		System.out.print("> ");
	}

	Point inputPoint() throws IOException{
		//a private HW1 method that reads in user input for new coordinates
		// and returns a new Point object at those coordinates

		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		String aline;
		int x,y;

		System.out.print("Enter x: ");
		aline=input.readLine();
		x=Integer.parseInt(aline);

		System.out.print("Enter y: ");
		aline=input.readLine();
		y=Integer.parseInt(aline);


		return (new Point(x,y));

	}

	void calculate(){
		//the private HW1 method that outputs/executes the appropriate calculations
		// note the first line is not required but demonstrates the usefulness
		// of defining toString for the Point class.

		System.out.println("Comparing " + pt1 + " to " + pt2+ ":");

		System.out.println("Distance: "+pt1.distanceTo(pt2));
		System.out.println("Direction: "+pt1.directionTo(pt2));
	}
	
	public static void main(String args[]) throws IOException{
		//the coveted "main" method that exists only to instantiate our
		//  HW1 object.

		HW1 test=new HW1();
	}

}
		




			
		

