/* This program repeatedly prompts the user for guesses until they correctly guess the Point the computer is thinking of. EXPECTED OUTPUT: I'm thinking of a point somewhere between (1, 1) and (5, 5) ... It is 4.47213595499958 from the origin. what is your x and y? 1 1 right up what is your x and y? 5 1 left up what is your x and y? 3 2 right what is your x and y? 4 2 you guessed it! */ import java.awt.*; import java.util.*; public class PointGuess { public static void main(String[] args) { Scanner console = new Scanner(System.in); Point answer = new Point(4, 2); Point origin = new Point(); double dist = answer.distance(origin); System.out.println("I'm thinking of a point somewhere"); System.out.println("between (1, 1) and (5, 5) ..."); System.out.println("It is " + dist + " from the origin."); System.out.println(); Point guess = getGuess(console); // continue looping until the user has got the right answer while (!guess.equals(answer)) { if (answer.x < guess.x) { System.out.print("left "); } else if (answer.x > guess.x) { System.out.print("right "); } if (answer.y < guess.y) { System.out.print("down"); } else if (answer.y > guess.y) { System.out.print("up"); } System.out.println(); guess = getGuess(console); // get next guess } // loop has ended, so user has guessed the right answer System.out.println("you guessed it!"); } // Asks the user for an (x, y) guess and returns it as a Point. public static Point getGuess(Scanner console) { System.out.print("what is your x and y? "); int x = console.nextInt(); int y = console.nextInt(); Point p = new Point(x, y); return p; } }