cs3101-003 Java
spring 2003
homework #1
due Wed Jan 29, by 6AM -- electronic submission

goal.
The goals of this assignment are to:

  1. write your first Java application
  2. practice using comments in your code
  3. learn how to use command-line input
  4. learn how to convert values from String to int
  5. practice using mathematical operators
  6. learn how to use if-else statements

program.
A robot and a treasure are located somewhere in a room (which is empty except for the robot and the treasure). The floor of the room is covered with square tiles, so you can think of the room as having a giant piece of graph paper covering its floor. The robot and the treasure each occupy a different tile in this grid, and you know the location of each one. The locations are specified using (x,y) coordinates.
Your job is to write a program that will take the coordinates of the robot and the treasure and then determine and provide directions to the robot for how to travel to the treasure. You can assume that the robot begins by facing in the positive Y direction. Your output will say something like "go forward 3 tiles, turn left, go forward 4 tiles".

You enter the coordinates using command-line arguments, as we did in class.

So, your program has to do the following:

  1. read 4 parameters from the command line, in the following order:
    1. x location of the robot
    2. y location of the robot
    3. x location of the treasure
    4. y location of the treasure
  2. echo the input (i.e., output it on the screen);
  3. determine and output directions for the robot to travel to the coin.

You can assume that the input values are all whole numbers. Your calculated outputs should be whole numbers in terms of the number of tiles to travel in each direction.

sample run.
Below is a sample run for two cases. The unix command line is highlighted in bold font.

unix$ java hw1eis2003 0 0 3 3
robot is at (0,0)
treasure is at (3,3)
go forward 3 tiles, turn right, go forward 3 tiles, stop.

unix$ java hw2eis2003 4 3 2 1
robot is at (4,3)
treasure is at (2,1)
turn around, go forward 2 tiles, turn right, go forward 2 tiles, stop.

source code.
Your source code (i.e., your .java file) must be neat and clearly commented. You must have a header comment and you should comment the end of each block (i.e., each }).

submission.

  • Name your Java file:
    hw1<yourCSusername>.java
    For example, mine would be called hw1sklar.java.
    BE SURE TO NAME YOUR FILE USING ALL lower case LETTERS!!!

  • Submit your program electronically.
    Instructions for submission will be posted on the class web page over the weekend.

    points.
    This assignment is worth 15 points (out of 100 for the semester). Distribution of points is: