THINK FIRST·CODE LATER

← All labs

Where is the point?

Problem

PointPosition reads the coordinates x y of a point and answers three questions:

  1. Is it inside, on the border of, or outside the circle of centre (0, 0) and radius 10?
  2. Is it inside (border included) the rectangle centred at (0, 0), 10 wide and 5 high?
  3. Is it the origin, on an axis, or in quadrant 1, 2, 3 or 4?

Do not use any Math method: compare the squared distance x² + y² with 10². For the input

4 5

the program prints

Circle: inside
Rectangle: outside
Position: quadrant 1

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l6-9-data-1.txt

4 5
What your program must print for l6-9-data-1.txt
Circle: inside
Rectangle: outside
Position: quadrant 1

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l6-9-data-1.txt

Windows PowerShell does not understand <:

Get-Content l6-9-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.