// SET INTERSECTION APPLICATION // Frans Coenen // Dept Computer Science, University of Liverpool // 7 July 1999 // Revised: Tuesday 30 august 2005 import java.util.*; class SetIntersectionApp{ // ------------------- FIELDS ------------------------ // Create Scanner class instance private static Scanner keyboardInput = new Scanner(System.in); // ------------------ METHODS ------------------------ /* Main method */ public static void main(String[] args) { // Create and input values for two sets. SetOperations set1 = createNewSetIOver2(); SetOperations set2 = createNewSetIOver2(); // Determine intersection SetOperations set3 = set1.intersection(set2); // Output System.out.println("Set1 = " + set1); System.out.println("Set2 = " + set2); System.out.println("Intersection = " + set3); } /* CREATE NEW SET IO VERSION 2: Method to allow input of set size and cause the creation of an instance of the class SetIOver2 */ private static SetOperations createNewSetIOver2() { // Input number of elements in set and then create instance // of set IO class. System.out.println("Input number of elements in set"); int setSize = keyboardInput.nextInt(); SetOperations newSet = new SetOperations(setSize); // Input for set if (setSize != 0) { System.out.println("Input values for set."); newSet.inputSet(); } else System.out.println(); // Return return(newSet); } }