CS1007
Fall 2001
Homework #2
due Tuesday 2 October 2001

last updated: Wed Sep 26 14:58:32 EDT 2001 / eis

goal. The goal of this assignment is to practice using the java.lang class, branching statements and command-line input.

create... a Java application program that takes two pairs of coordinates as input, representing the locations of a robot and a soccer ball within a rectangular field.

Pretend that the field is a piece of graph paper, where the center of the field is (0,0) of a Cartesian coordinate system. The first pair of coordinates represents the location of the robot. The second pair of coordinates represents the location of the ball. Here's an illustration:

The larger, blue dot represents the robot.
The smaller, black dot represents the ball.
The X and Y axes are drawn to help the illustrate the imaginary coordinate system.

1. read input... The two input pairs of coordinates should be entered on the command line. For example:
unix$ java hw2eis2003 -1 2 3 9
would mean that the robot is at location (-1,2) and the ball is at location (3,9).

2. check input... The program should first check that four numbers were entered on the command line. If not, then the program should print a usage error and exit.

3. echo input... The program should next convert and store the four input coordinates as int variables, and echo them to the screen. For example, given the command line input (above), the output would be:
robot is at position (-1,2)
ball is at position (3,9)

4. compare locations... The program should next compare the location of the robot to the location of the ball and print out the compass direction from the robot to the ball. This direction must be one of: north, south, east, west, northeast, northwest, southeast, southwest, or, if the robot and the ball are in the same location, then print that the ball is on top of the robot.
For example, given the command-line input (above), the program would output:
the ball is northeast of the robot

5. calculate distance... The program should next calculate the distance from the robot to the ball and print that out.
For example, given the command line input (above), the output would be:
distance=8.06225774829855

6. calculate angle... The program should next calculate the angle that the robot must turn to in order to be facing the ball; and the program should print out that angle. You can assume that the robot is facing due east (along the positive X axis) and that the angle is measured in radians, counterclockwise.
For example, given the command line input (above), the output would be:
angle=1.051650212548374 radians

7. extra credit... Output the angle (from the previous step) in degrees. For example, given the command line input (above), the output would be:
angle=60.255118703057796 degrees

8. submit... Your program file MUST be named hw2<yourCUNIXusername>.java. For example, mine would be called hw2eis2003.java. BE SURE TO NAME YOUR FILE USING ALL lower case LETTERS!!!
Submit your program in two ways: electronically and hard copy. Check the assignments link on the class home page for submission instructions.

here's a complete sample run...
unix$ java hw2eis2003 -1 2 3 9
robot is at position (-1,2)
ball is at position (3,9)
the ball is northeast of the robot
distance=8.06225774829855
angle=1.051650212548374 radians
angle=60.255118703057796 degrees