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.

  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 the console testing application that you started in the lab to include appropriate test cases for these new features.

  2. 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:

    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.

  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 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.

  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 console application that starts the watch and prompts the user to stop it. Make sure to check all the operations of the stop watch.

  5. A real estate agency wants a simple way to keep track of houses for sale. Design and build a 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:
    1. Default and explicit value constructors (that maintain the invariants).
    2. Accessors for each instance variable.
    3. A toString() method that prints using this format: 3201 Burton SE (6 beds, 3.5 baths).
    4. A helper method that computes the base price for a property: One bedroom contributes $100000, and each additional adds 25000. One bathroom contributes 10000, each additional bathroom adds 5000.
    You do not need to include any mutators.

    Write a console test application that tests your methods on at least five different properties. Be sure to include tests for invalid property records.

Checking In

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.