Hands on Testing Java: Lab #7

Homework Projects

Configure Your Project

  1. Create a file named Design/project07.txt.
  2. Create a new package in your project named edu.INSTITUTION.USERNAME.hotj.project07.
  3. Create the classes needed for the assigned project as part of the edu.INSTITUTION.USERNAME.hotj.project07 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 #7.1: Write a menu-driven "police sketch artist" driver using ASCII art wikipedia. The program should use four different menus for:

Each menu must provide at least three different choices.

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

Implement this program using two supporting classes.

With these two classes, you can write a FaceCLIDriver to implement the program described above: using a FaceInput instance, it will go through each of the four facial components, call the the appropriate FaceInput method for each component, and then finally genereate the ASCII art from the Face attribute of the FaceInput instance.

Run the driver at least ten times in your sample execution (as well as the FaceTest test-case class).

Project #7.2: Write a class Year which has just a year attribute (an integer); a negative number will represent years "Before Christ" ("B.C.").

Write a Year#toString() method that returns a String like "A.D. 2005" and "376 B.C.".

Write a method Year#isLeapYear() that returns true if that year is a leap year, and returns false otherwise. 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 was 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 JUnit test-case class that thoroughly tests your methods. You do not have to write a driver.

Write an OCD for the Year#toString() method.

Project #7.3: Using the Metric class you created in lab 4, write a menu-driven driver that permits the user to select and perform any one of the metric conversions available. There's no JUnit test-case class to write.

Project #7.4: Create a LetterGrade class whose instances keep track of letter grades F, D, C, B, and A (represented as a single char). Create two constructors: one that receives a char, and another that receives a real number between 0 and 100. This second constructor should initialize the letter grade appropriately (use a 60/70/80/90 grading scale). It's completely unnecessary to save this numeric score.

Write at least two "accessor" methods: one to return the letter grade itself, and another to return a numeric score on a 4 points scale (4.00 for an 'A', 3.00 for a 'B', etc.).

Write a JUnit test-case class to test LetterGrade objects and its methods. No driver is necessary.

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