CS1004 Homework #2
Due on February 22, 2005 at 11:00am

There are two parts to this homework: a written component worth 12 points, and programming component worth 13 points.  Submission instructions are available here.

Written questions

As to be described later in the homework submissions instructions, you may submit this as a hardcopy, or as a file along with your programming problems in one of four formats (Word, PDF, HTML, or plaintext).

Note that problems assigned from Schneider/Gersting or Lewis/Loftus are the exercise problems at the end of each chapter, not the practice problems or self-review questions.  (The practice/self-review problems are optional, and solutions for them are provided in the book.  For obvious reasons, the solutions for the exercises are not. ;-))

  1. (3 points) Schneider/Gersting exercise 1.7.
  2. (2 points) Schneider/Gersting exercise 4.1.
  3. (1 point) Schneider/Gersting exercise 4.2.
  4. (3 points) Schneider/Gersting exercise 4.7.
  5. (3 points) Lewis/Loftus exercise 2.6a,c,e,h,j,m.

Programming problems

As described below, you will submit this part of the assignment as five files: three .java files, corresponding to the source for each problem, a .html file to run problem 3, and a README file (no typescript is necessary).  Suggestion: do each of the problems in order, as they're of increasing difficulty.

  1. (3 points) Write a Java program called BeanCounter, which performs a few simple arithmetic operations on a pair of variables and prints the results to the screen. More specifically, your program should create two variables of type integer (call them var1 and var2), assign them default values (they should be non-zero, but they do not need to be acquired via interactive input), perform the following calculations and print the results of each out on the screen. The operations you need to implement are:

    Sample Output for java BeanCounter:

    * The sum of 50 and 20 is 70
    * The product of 50 and 20 is 1000
    * 50 divided by 20 is 2.5
    * 50 % 20 is 10
    * I computed (50+20)*(70+2.5)/10+1000 to equal 1507.5
    * 50 > 20 is true

  2. (4 points) Lewis/Loftus programming project 2.8 (pp. 110): Using the Scanner class, write a Java program, called CoinCounter, that reads integer values (from System.in) representing the number of pennies, nickels, dimes, and quarters, and outputs the (floating-point) total in dollars to the screen.
  3. (6 points) Write a Java applet, called FaceApplet, that draws a person's face.  (For inspiration, feel free to use your own, a friend's, your instructor's, Lee Bollinger's, what have you.)  At a minimum, your face must consist of the following components and at least two colors other than black and white (e.g., skin and hair tones).
    1. The face itself (oval?  circle?)
    2. Some attempt at hair (at least one single hair follicle)
    3. Ears
    4. Eyes and nose
    5. Mouth (doesn't have to be open)
    6. A caption below the face explaining what it is. (If you don't want to reveal the source of your inspiration, feel free to make the caption abstract, e.g., "My muse" or somesuch.)
    The face doesn't have to be fancy; we're not testing your art skills, and a bunch of polygons/ovals are sufficient, although your assignment should show some effort (i.e., ears that don't actually attach to the head may lose credit).  However, particularly elegant attempts at art will be given up to one point of extra credit.  For fun, feel free to put the applet on your website (although this is not required; you will submit your code electronically).  (Hint: use Lewis/Loftus' book examples, in particular the snowman on page 103, as a model for what you need to do.  You may also find the Java API documentation for the Graphics class to be of help in figuring out the kinds of things you can draw.)