Hands on Testing Java: Lab #8

Homework Projects

Configure Your Project

  1. Create a file named Design/project08.txt.
  2. Create a new package in your project named edu.INSTITUTION.USERNAME.hotj.project08.
  3. Create the classes needed for the assigned project as part of the edu.INSTITUTION.USERNAME.hotj.project08 package.

The Projects

Your instructor will assign you one of the problems below. To solve your problem, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible. Following the pattern in the lab exercise, first, design using OCD. Then code your design in Java using stepwise translation. Test your program thoroughly.

When executing your program to hand in as part of the project, a JUnit test case should test each method at least five times, but the test case itself needs to be executed just once. A driver program should be run at least five times with different inputs each time.

Project #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".

It is tricky writing good unit testing for this project, so write a really good driver.

Project #8.2: Add a factorial() operation to the Calculator class that, given an integer n, computes n! = 1 * 2 * ... * (n-1) * n. This new function can safely ignore the second operand.

Add new tests to the CalculatorTest class for the new function. Also adapt your driver (as necessary) to access the new computation.

Project #8.3: Redesign Calculator#power() so that it handles negative exponents (i.e., x^-n for n > 0 is the same as 1/x^n).

Add new tests to the CalculatorTest class for the new function. Also adapt your driver (as necessary) to access the new computation.

Project #8.4: Add a function to the Calculator class to compute the 3n+1 problem. The first operand in the calculator should be taken as n; ignore the second operand. Compute a new value for n as follows:

Repeat until you reach n=1. The Calculator should return how many times n is changed. (n=1 changes n 0 times; n=2 changes n 1 time.)

Add new tests to the CalculatorTest class for the new function. Also adapt your driver (as necessary) to access the new computation.

Project #8.5: Write a UnitedStatesOfAmericanFlag class with no instance variables. The purpose of this class is to generate the U.S. flag in ASCII art wikipedia (although, since Java uses Unicode instead of ASCII, perhaps it's better to call this "Unicode art").

Write three ASCII art methods:

  1. generateASCIIArt() which returns a String of the whole flag. Use the next two methods!
    * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     * * * * *
    * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     * * * * *
    * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     * * * * *
    * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     * * * * *
    * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
  2. generateStripe(n,ch) that displays n consecutive ch characters (e.g., printStripe(5,'X'); should display XXXXX.)
  3. generateAlternating(n,ch1,ch2); that displays n consecutive pairs of the characters ch1ch2 (e.g., printAlternating(3,'X','Y'); should display XYXYXY.)

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

Unit test all three methods (plus your additional methods). Write a driver that displays the flag.

Write an OCD for the generateStripe(n,ch) method.

Project #8.6: Build a "police sketch artist" program as described in Project #7.1, but write a dynamic program that lets the user experiment with different combinations of facial parts in a single execution.

Start with the Face and FaceInput classes as described in Project #7.1. Your FaceCLIDriver for this project is more elaborate/useful.

This driver starts with a 'blank' face and allows the user to modify this face using a two-level menu system.

Both menu levels should be implemented in loops which require the user to explicitly quit that particular menu. Also, the face should be printed out just before the menu choice is made.

Reuse the Menu class from the lab exercise to greatly reduce your work.

Run your test-case class (of course); run the driver at least twenty times as part of your sample execution. Be sure to demonstrate strange situations: what if the user quits a menu right away? what the user enters in bad data? how often can the user enter in bad data? how fast can you construct an interesting face (i.e., with the least input)? how long can you spend constructing a face?

Project #8.7: Use the Fraction class from Lab #6 to create a "drill" program that generates random fractions (using class java.util.Random), that grade-school students can use to practice their fractional arithmetic.

Be sure to include the unit testing from that lab, and this project will add a new driver.

Turn In

Turn the following things:

  1. This grade sheet
  2. An OCD design for one of your methods.
  3. All source files you created for your project.
  4. Sample executions of your test cases and drivers (as applicable).

Lab Home Page | Prelab Questions | Lab Exercise | Homework Projects