CSE 283 Introduction to Object Oriented Design

Barbara Nostrand, Ph.D.


CSE 283 Labs
Welcome to the site for CSE 283 Labs!

 

Lab 7-8: Projects

Prev | Next | Lab 7-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. Write a menu-driven "police sketch artist" program called Artist. The program should use four different menus for:

  • hairstyle (e.g., bald, crewcut, curly, wearing a hat)
  • eyes (e.g., beady, bug-eyed, glasses, closed)
  • nose (e.g., pug, small, medium, large)
  • mouth (e.g., puzzled, smiling, bearded, frowning)

Each menu must provide at least four different choices. Your program should display "sketches" of the person being described, along the lines of those below (hopefully yours will be better!):


      -----
     |     |        .......     \|||||||/
    ---------       .     .      |     |
    (| O O |)      (|-0-0-|)    (| . . |)
     |  _\ |        |  ^  |      |  >  |
     |\___/|        | --- |      |||-|||
      -----          -----        |||||
                                   ||| 

Organize your program in such a way that it contains no redundant code. For each of the user's choices, write a separate method to process that choice.

Then modify your program to make it dynamic so that the user can 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.

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

Prev | Next | Lab 7-8

 
  Home

Schedule

Help

Lab 0

Lab 1

Lab 2

Lab 3

Lab 4

Lab 5

Lab 6

Lab 7-8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13






Last modified: 2007 OCT 16
bnostran@syr.edu