Hands On Java: Project 8


 

Objectives

1. Practice designing programs that use loops.
2. Practice choosing the appropriate kind of loop for a problem.

Introduction

Your instructor will assign you one of the following projects, each of which uses loops controlled by conditions.

Projects

8.1. Write a program that will read a sequence of numbers from the keyboard, and display the minimum, maximum, average, and range of the entered values. Make the input step "foolproof".

8.2. Extend Calculate.java into a six-function calculator, as follows:

  1. Add a factorial() operation that, given an integer n, computes n! = 1 * 2 * ... * (n-1) * n.
  2. Redesign power() so that it handles negative exponents.

8.3. Write two "graphics" methods:

  1. printStripe(n, ch); that displays n consecutive ch characters. (e.g., printStripe(5, 'X'); should display XXXXX.)
  2. printAlternating(n, ch1, ch2); that displays n consecutive pairs of the characters ch1ch2. (e.g., printAlternating(3, 'X', 'Y'); should display XYXYXY.)

Use these methods to write a program that draws a picture, such as a flag. For example, you might use these methods to draw a crude facsimile of the U.S. flag that looks like this:

   * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    * * * * * 
   * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    * * * * * 
   * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    * * * * * 
   * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    * * * * * 
   * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Try and draw your picture efficiently (i.e., using loops to minimize the number of statements). Feel free to create additional "graphics" methods that simplify drawing your particular flag.

8.4. Build a "police sketch artist" program as described in Project 7.2, but write a dynamic program that lets the user experiment with different combinations of facial parts in a single execution. (Hint: Control the program using a loop. Start with a 'blank' face. Allow the user to modify this face using a two-level hierarchical menu, with the first level allowing the user to select which facial part they want to modify (i.e., a menu of menus), and the second level allowing the user to select from among the choices for that particular facial part.)

8.5. Use the Fraction class from lab 6 to create a "drill" program that generates random fractions (using class java.util.Random), that younger students can use to practice their fractional arithmetic.

Turn In: A hard copy of this grade sheet, attached to hard copies of

  1. all source files you created for this project; and
  2. the output from an execution of your executable program.

Don't forget to clean up your directory when you are all finished...


Back to the Lab Exercise

Back to This Lab's Home Page


 

Back to the Table of Contents

Back to the Introduction


Copyright 2000 by Prentice Hall. All rights reserved.