CS 1063  Lab 6:  Designing and Implementing a Class using Assignment Statements

The Pair Class

Objectives

Hand-in Requirements

All projects and laboratories will be submitted electronically through webCT.  Zip up your entire project folder to submit as the source.  (Right click on the project folder and follow the SentTo link.)   The project directory should include the following:

Details

Write a program that implements the class Pair.  A Pair class contains two double numbers and performs various operations on the two numbers.  In the constructor supply the two double numbers necessary for the pair.

Your program should contain methods to do the following
  1. toString that returns the state of the Pair as a String
  2. Return the values stored in the two numbers.  Methods getFirst and getSecond
  3. Calculate and return the sum of the two numbers
  4. Calculate and return the difference of the two numbers (first - second)
  5. Calculate and return the product of the two numbers
  6. Calculate and return the quotient of the two numbers (first/second)
  7. Calculate and return the distance of the two numbers (absolute value of the difference)
  8. Calculate and return the average of the two numbers
  9. Calculate and return the maximum (the larger of the two)

    To find the maximum of the two double numbers use the static method Math.max.  (That is, max is a static method in the Math class).

    double maxValue = Math.max(5.0, 6.0);  // maxValue = 6.0
    
  10. Calculate and return the minimum (the smaller of the two) 

    To find the minimum of the two double numbers use the static method Math.min.  (That is, min is a static method in the Math class).

    double minValue = Math.min(5.0, 6.0);  // minValue = 5.0
    

Remember to follow the steps we have used in class.  Determine the public interface, start typing in your class using stubs, and then fill in your implementation.

Testing your Class

Test ALL of your methods with three different Pair objects.  In your first pair make the first number greater than the second, in the second pair make the second number greater, and in the third pair make the two numbers equal.