CS100 Spring 2000

Professors David I. Schwartz & Thomas Yan

Project 2: The Target Strikes Back (aka, Loops Ahoy!)

Due: Thursday, February 10, 2000

Required Problems

   Solve all required Problems 1-4.  Note that we have deliberately
   under-specified some of these problems.  Use your best judgement and
   document your code clearly.  You may not use arrays for any of the following
   problems.  You must use TokenReader to gather all input.  You may use the
   space/paper saving techniques posted to the newsgroup for printing programs
   and output.
	
1. Do Programming Project 2.11 from Lewis&Loftus.  Name the program
   Project2_1.  Thus, the Main Class should have the name Project2_1.  Hint:
   You will have to change the Java target setting for CodeWarrior.

   Demonstrate your program with the following data.  The total amount of gas
   used is 5 gallons.  The start and end readings of the trip-odometer are 13
   and 140 miles, respectively.

2. Write a program called Project2_2 to: (1) Read in a sequence of positive
   integers -- a non-positive integer terminates the sequence (2) Print the
   number of multiples of 5 found in the sequence.

   Demonstrate your program with the following input sequences:

   o	5, 21, 1, 21, 25, 32, -1
   o	0, 5, -1 (Hint: What should the program do if the user enters zero?
		  Beware of what positive means!)  
   o	150, -1

3. Write a program called Project2_3 to: (1) Read in a sequence of integers
   between -100 and 100, inclusive -- an out-of-range number terminates the
   sequence (2) Print the number of sign changes for the sequence.  Recall that
   there are three different signs: +, 0, and -.

   Demonstrate your program with the following input sequences:

   o	-99, -97, 12, -10, 1, -2, 101
   o	1, -1, 0, 1, -1, 101
   o	1, -101
   o	2000

4. Write a program called Project2_4 to: (1) Read in a sequence of elevations
   from a contour map, terminated by -1 (2) Print the two neighboring
   elevations with the steepest gradient.  The gradient G between elevations x
   and y is G=|x-y|, assuming constant spacing between measurements.

   Demonstrate your program with the following input sequences:

   o	52, 63, 63, 95, 100, -1
   o	0, -1

Bonus Problem

   The following problem is optional and, consequently, worth bonus points: Do
   Programming Project 2.9 from Lewis&Loftus.  The Main Class should have the
   name Project2_B.

What To Submit

   Follow the submission instructions and other procedures from the Projects
   page on the CS100 Course Website.  Include all programs and output.