Hands On Java: Project 7



1. Practice using selective behavior.
2. Practice constructing conditions.
3. Practice program maintenance.


Your instructor will tell you which one of the following projects to do.


7.1. There are three possible sources of user error in Calculate.java:

  1. The user could enter an invalid operation (something other than +, -, * or /).
  2. The user could enter / for operation and 0 for op2 (i.e., a divide-by-zero error).
  3. The user could enter a nonnumeric value for op1 or op2.

Our program uses Assertion.check() to guard against the first two kinds of errors, but the diagnostic message displayed by Assertion.check() is not particularly informative or user-friendly. Replace each of the calls to Assertion.check() in Calculate.java with a selective-behavior statement that displays a more user-friendly diagnostic message and terminates the program (using System.exit(1) ) if the user enters erroneous information.

7.2. Write a menu-driven "police sketch artist" program. The program should use four different menus for:

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.

7.3. A year is a leap year if it is evenly divisible by 4, unless it is divisible by 100, in which case it must also be divisible by 400. That is, 1996 was a leap year because it is divisible by 4 and not 100, 1997 was not a leap year because it is not divisible by 4, 2000 is a leap year because it is divisible by 4 and 400, but 2100 will not be a leap year because it is divisible by 4 and 100 but not 400.

Write a leapYear() method that, given a year, returns true if that year is a leap year, and returns false otherwise. Then write a driver program that tests your method.

7.4. Using the Metric class you created in lab 4, write a menu-driven program that permits the user to select and perform any one of the metric conversions available.

7.5. Create a Grade class that has shared (static) variables for the cutoffs for each of the grades D, C, B, and A. It should have shared (static) methods to set each of these cutoffs. The constructor should take one argument, the score, which is a double. It should have one method which computes and returns the grade for that score.

Write a program that demonstrates the correctness of your implementation of the Grade class.

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.