CS1007
Fall 2002
Homework #2
due Tue Oct 1, by 6AM -- electronic submission

hardcopy due IN CLASS by 2.45PM

last updated: Fri Sep 20 17:24:08 EDT 2002

goal.
The goals of this assignment are to:

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

program.
You have two robots. Each robot has 4 wheels, two of which are connected to motors. These are called drive wheels. You know the diameter of each robot's drive wheels, and you know the rotation rate of the motors (i.e., how many times per second the wheels go around). You need to determine which robot will travel farther during a given time period.

Your program has to do the following:

  1. read 5 parameters from the command line, in the following order:
    1. the diameter of the drive wheels of robot #1 (in cm)
    2. the diameter of the drive wheels of robot #2 (in cm)
    3. the rotation rate of the motor of robot #1 (in rps)*
    4. the rotation rate of the motor of robot #2 (in rps)*
    5. time (in sec)
    *rps = revolutions per second
  2. echo the input;
  3. determine and output the distance travelled by each robot in the given time;
  4. determine and output which robot travels farther.

You can assume that the input values are all whole numbers. Your calculated outputs should be real numbers.

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

unix$ java hw2eis2003 3 5 3 3 5
ROBOT #1: diameter = 3cm
          rate     = 3rps
ROBOT #2: diameter = 5cm
          rate     = 3rps
time     = 5sec
robot #1 went 141.3716694115407cm
robot #2 went 235.61944901923448cm
robot #2 travelled farther

unix$ java hw2eis2003 1 2 3 4 5
ROBOT #1: diameter = 1cm
          rate     = 3rps
ROBOT #2: diameter = 2cm
          rate     = 4rps
time     = 5sec
robot #1 went 47.12388980384689cm
robot #2 went 125.66370614359172cm
robot #2 travelled farther

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

submission.
Follow the submission instructions carefully!!! If you don't, human intervention will be required to fix your mistakes, and you will lose 1 point.

  1. Name your file properly.
    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!!!

  2. Submit your program electronically.
    Follow instructions on the assignments page.

  3. Turn in a harcopy of your program during THE FIRST 5 MINUTES OF class.
    Print out the homework template cover page (http://www.columbia.edu/~cs1007/hw-template.html) and fill it out.
    Staple the cover page to a hardcopy (print-out) of your program (the Java source code, e.g., the file named hw2eis2003.java). Make sure your name is on all the papers you hand in!
    Bring the cover page and hardcopy to class on the day the assignment is due and deposit it in the homework box at the front of the classroom within the first 5 minutes of the class.

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

hints.
Start building your program from a working version of homework #1, and modify that code. Always make small changes, compile and run them to make sure they work. This way you always have code that compiles and runs -- you may have a partial solution, but a partial solution that compiles and runs is better than a complete solution that doesn't compile or run. Because if it doesn't compile or run, it's not a complete solution.