Assignment 7 Write a generic class Pair which has two type parameters—F and S—each representing the type of the first and second element of the pair, respectively. Add set and get methods for the first and second elements of the pair. (Hint: The class header should be public class Pair.) Write a separate PairTest class to test class Pair. Create 2 Pair types and test your get and set methods on the following pair types: • Pair p1 takes Integer and String types as a pair • Pair p2 takes String and Integer PairTest should output enough information to the terminal to show that your generic class Pair is able to set() and get() different types. Solution ANS: // Pair contains two types. public class Pair< F, S > { private F first; // first element of a pair private S second; // second element of a pair // constructor public Pair( F firstElement, S secondElement ) { first = firstElement; second = secondElement; } // end Pair constructor // get first public F getFirst() { return first; } // end method getFirst // get second public S getSecond() { return second; } // end method getSecond // set first public void setFirst( F firstElement ) { first = firstElement; } // end method setFirst // set second public void setSecond( S secondElement ) { second = secondElement; } // end method setSecond } // end class Pair // Generic Pair class testing program. public class PairTest { public static void main( String args[] ) { // create pair of integer and string Pair< Integer, String > numberPair = new Pair< Integer, String >( 1, \"one\" ); // display original numberPair System.out.printf( \"Original pair: < %d, %s >\ \", numberPair.getFirst(), numberPair.getSecond() ); // modify pair numberPair.setFirst( 2 ); numberPair.setSecond( \"Second\" ); // display modified numberPair System.out.printf( \"Modified pair: < %d, %s >\ \", numberPair.getFirst(), numberPair.getSecond() ); } // end method main } // end class PairTest .