package rectangletest;

import java.util.*;
/*Nathan Hughes - 1809708   
public class RectangleTest {

    public static int[] GetCoords() {
        Scanner scan = new Scanner(System.in);
        int[] coords = new int[4];
        
        /* coords[0] : x coord of botleft  vert
           coords[1] : y coord of botleft  vert
           coords[2] : x coord of botright vert
           coords[3] : y coord of topleft  vert
        */
        
        System.out.println("Enter the coordinates of two of the rectangles vertices, ensuring that they are NOT colinear.");
        System.out.println("Enter x coordinate of first vertex: ");
        int coordx1 = scan.nextInt();
        System.out.println("Enter y coordinate of first vertex: ");
        int coordy1 = scan.nextInt();
        System.out.println("Enter x coordinate of second vertex: ");
        int coordx2 = scan.nextInt();
        System.out.println("Enter y coordinate of second vertex: ");
        int coordy2 = scan.nextInt();
                
        coords[0] = Math.min(coordx1, coordx2);
        coords[1] = Math.min(coordy1, coordy2);
        coords[2] = Math.max(coordx1, coordx2);
        coords[3] = Math.max(coordy1, coordy2);
           System.out.println(coords[0]);
           System.out.println(coords[1]);
           System.out.println(coords[2]);
           System.out.println(coords[3]);
        return coords;
    }
    
    public static void PointTester(int[] rect) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Testing points. Enter 'exit' to exit.");
        String ans="";
        while(true) {
            System.out.print("Enter x the coordinate of your test point:");
            ans = scan.nextLine();
            if (ans.equals("exit")) {
                System.out.println("Goodbye");
                return;
            } 
            int pointx = Integer.valueOf(ans);
            System.out.print("Enter y the coordinate of your test point:");
            ans = scan.nextLine();
            if (ans.equals("exit")) {
                System.out.println("Goodbye");
                return;
            } 
            int pointy = Integer.valueOf(ans);
            if (pointx > rect[0] && pointx < rect[2]) {
                if (pointy > rect[1] && pointy < rect[3]) {
                    System.out.println("("+pointx+","+pointy+"): Inside rectangle");
                } else if (pointy == rect[1] || pointy == rect[3]) {
                    System.out.println("("+pointx+","+pointy+"): On rectangle edge");
                } else {
                    System.out.println("("+pointx+","+pointy+"): Outside rectangle");
                }
            } else if (pointx == rect[0] || pointx == rect[2]) {
                if (pointy < rect[1] || pointy > rect[3]) {
                    System.out.println("("+pointx+","+pointy+"): Outside rectangle");
                } else {
                    System.out.println("("+pointx+","+pointy+"): On rectangle edge");
                }
            } else {
                System.out.println("("+pointx+","+pointy+"): Outside rectangle");
            }
        } 
    }
    
    public static void main(String[] args) {
        int[] rect = new int[4];
        rect = GetCoords();
        PointTester(rect);
    }
}

/* I have tested this program, but I removed them instead of commenting them out. I don't know why I did that. */