Your instructor will assign one or more of the following problems. Submit all appropriate files for grading, including code files, screen captures, supplemental files (e.g., image files), and text files.
Extend the
Fraction
class by adding these methods:
double
equivalent of the fraction.
Name the relational operators with an
is
- prefix:
isEquals(Fraction)
,
isNotEquals(Fraction)
, etc. This will avoid a technical problem or two.
Extend the console testing application that you started in the lab to include appropriate test cases for these new features.
A quadratic equation has the form
ax^2 + bx + c
where the coefficients
a
,
b
, and
c
are all real values, and
a
cannot be zero. Write a class
Quadratic
that can be used to model a quadratic equation. You’ll need
constructors (that maintain the invariant), accessors, and a
toString()
method (but no mutators). Also include two computation methods:
x
.
b^2 - 4ac
, if greater than or equal to zero).
Write a console test application that tests your methods on at least five different quadratic equations. Be sure to include tests for zero and negative coefficients.
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
a
PhoneNumber
object, access each of its attributes, and indicate whether or not
the number is long-distance. Finally, add a method that compares two
phone numbers and indicates whether they have the same area code.
Note that 911 is not a valid area code. The toString() method should
present a local number differently from the way it displays a
long-distance number (e.g.,
555-1234
vs.
(616) 555-1234
).
Your instructor may also ask you to implement input and output operations. The input operation should read a local or long-distance number and set the long-distance indicator accordingly.
Write a console application that tests the basic operations of this class.
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 console application that starts the watch and prompts the user to stop it. Make sure to check all the operations of the stop watch.
PropertyRecord
class
that models a property. Each property will have a street address, a
number of bedrooms (integer) and a number of bathrooms (double -- a
half bathroom does not have a shower/tub). The number of bedrooms and
bathrooms must both be at least one. Your design should include
the following:
toString()
method that prints using this
format: 3201 Burton SE (6 beds, 3.5 baths).
Write a console test application that tests your methods on at least five different properties. Be sure to include tests for invalid property records.
Submit all appropriate files for grading, including code files, screen captures, supplemental files (e.g., image files), and text files. We will grade this exercise according to the following criteria:
If you work in teams for this homework assignment, be sure to submit all team members’ names in the code documentation.