Hands on Testing Java: Lab #6

Homework Projects

Configure Your Project

  1. Create a file named Design/project06.txt.
  2. Create a new package in your project named edu.INSTITUTION.USERNAME.hotj.project06.
  3. Create the classes needed for the assigned project as part of the edu.INSTITUTION.USERNAME.hotj.project06 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 #6.1: Extend the Fraction class by adding these methods:

Name the relational operators with an is- prefix: isEquals(Fraction), isNotEquals(Fraction), etc. This will avoid a technical problem or two.

Extend your JUnit test-case class to test your new methods.

Project #6.2: A quadratic equation has the form

ax^2 + bx + c

where the coefficients a, b, and c are all real values. Write a class Quadratic that can be used to model a quadratic equation. You'll need constructors and accessors (but no mutators). Also include three computation methods:

The last two method use the quadratic equation.

Write a JUnit test case that test your methods on at least five different quadratic equations. Be sure to include tests for zero and negative coefficients.

Project #6.3: A phone number consists of four separate pieces of information: an area code, an exchange, a local number, and a long-distance indicator (true or false). Design and build a PhoneNumber class that models a phone number, providing operations to construct, input, output, access each of the attributes of a PhoneNumber object, and indicate whether or not the number is long-distance. The input operation should read a local or long-distance number and set the long-distance indicator accordingly. The output operation should display a local number differently from the way it displays a long-distance number (e.g., 555-1234 vs. (616) 555-1234).

Write a simple test case class that tests the basic operations of this class.

To test your class, write a driver that simulates an intelligent computer modem dialer by reading a PhoneNumber, and displaying the number to be dialed. If the number is a long distance number, it should be preceded by 1-; otherwise it should be displayed as a local number.

Project #6.4: A dual stop watch can time two runners simultaneously. It has one button to start the timer and two buttons to stop the timer (one for each runner). It will have three attributes for keeping track of the time: a start time and for each runner a stop time. It will also have two attributes that indicate the state (running or not running) of the stop watch for each runner. Design and build a DualStopWatch class that models a stop watch. Your class should provide operations to construct, start timing, stop the timer for either runner, and display the time for either runner. If the stop watch is running, you should display the current elapsed time. If the watch is not running you should display the final elapsed time.

Hint: You can get the current system time in milliseconds using the class java.util.Date via this code:

long current = (new Date()).getTime();

To test your classes, write a program that starts the watch and prompts the user to stop it. Make sure to check all the operations of the stop watch.

Turn In

Turn the following things:

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

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