/////// File Rect.java /////// import java.io.*; class Rect { public static Vector2D getPoint(int i) throws IOException { String s; float x = 0.0f, y = 0.0f; BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); System.out.print("x"+i+"= "); System.out.flush(); s = in.readLine(); x = Float.valueOf(s).floatValue(); System.out.print("y"+i+"= "); System.out.flush(); s = in.readLine(); // read keyboard input as string y = Float.valueOf(s).floatValue(); return(new Vector2D(x,y)); } public static void main(String args[]) throws IOException { int i; System.out.println("Enter vertices 0, 1, 2, 3"); Vector2D[] point = new Vector2D[4]; for ( i = 0; i < 4; i++) point[i] = getPoint(i); for ( i = 0; i < 4; i++) System.out.print(point[i] + " "); Vector2D v; Vector2D u = point[1].minus(point[0]); for ( i = 0; i < 3; i++) { v = point[(i+2)%4].minus(point[i+1]); if ( ! u.isPerpendicular(v) ) { System.out.println("No, not a rectangle."); return; } u = v; } System.out.println("Yes, a rectangle."); } }