Programming Exercises

graphics/pe_icon.gif

10.1

Create a class named Pair, which aggregates two arbitrary objects. Implement the equals() and hashCode() methods in such a way that a Pair object is identical to another Pair object if, and only if, the pair of constituent objects are identical. Make the toString() implementation return the textual representation of both the constituent objects in a Pair object. Objects of the Pair class should be immutable.

10.2

A palindrome is a text phrase that spells the same thing backward and forward. The word redivider is a palindrome, since the word would spell the same even if the character sequence were reversed. Write a program that takes a word as an argument and reports whether the word is a palindrome.