Design/project06.txt
.edu.INSTITUTION.USERNAME.hotj.project06
.edu.INSTITUTION.USERNAME.hotj.project06
package.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:
- Three more arithmetic operations (+, -, and /).
- Six relational operations (==, !=, <, >, <=, and >=).
- Compute the reciprocal of a fraction (i.e., the reciprocal of n/d is d/n).
- Convert a fraction into a
double
equivalent.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 + cwhere the coefficients
a
,b
, andc
are all real values. Write a classQuadratic
that can be used to model a quadratic equation. You'll need constructors and accessors (but no mutators). Also include three computation methods:
- One method returns the value of the quadratic equation for a specified value for
x
.- Another method will return the larger of the two possible solutions for
ax^2+bx+c = 0
.- The last will return the smaller of the two possible solutions for
ax^2+bx+c = 0
.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 aPhoneNumber
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 by1-
; 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 the following things:
Lab Home Page | Prelab Questions | Lab Exercise | Homework Projects