Question: import java.util.*; public class SetExample6 { public static void main (String[] argv) { // Read from file and get an array, one array element for

 import java.util.*; public class SetExample6 { public static void main (String[]

import java.util.*; public class SetExample6 { public static void main (String[] argv) { // Read from file and get an array, one array element for each person. // Thus, people[i] is of type DataSet and people[i].strings has // all the strings associated with the i-th person. DataSet[] people = DataTool.getDataSetsAsArray ("datafortwo"); System.out.println ("Intersection between " + people[0].name + " and " + people[1].name); computeIntersection (people[0].strings, people[1].strings); } static void computeIntersection (LinkedList listA, LinkedList listB) { for (int i=0; i 

import java.io.*; import java.util.*; public class DataTool { public static DataSet[] getDataSetsAsArray (String fileName) { LinkedList allDataSets = getDataSets (fileName); DataSet[] sets = new DataSet [allDataSets.size()]; for (int i=0; i getDataSets (String fileName) { String line = null; int lineNum = 0; try { LineNumberReader lnr = new LineNumberReader (new FileReader (fileName)); LinkedList allDataSets = new LinkedList(); line = lnr.readLine (); lineNum = 1; DataSet data = null; while (line != null) { line = line.trim(); if (line.startsWith ("#")) { // First end previous round. if (data != null) { allDataSets.add (data); } // Start a new data set. data = new DataSet (); data.name = line.substring (1, line.length()); data.strings = new LinkedList(); } else { data.strings.add (line.trim().toLowerCase()); } line = lnr.readLine(); lineNum ++; } //endwhile // Last data set. if (data != null) { allDataSets.add (data); } return allDataSets; } catch (Exception e) { // If something went wrong ... System.out.println ("ERROR in file at line# " + lineNum + ": " + line); System.out.println (e); System.exit (0); return null; } } public static void main (String[] argv) { // Test. DataSet[] data = getDataSetsAsArray ("bookdata"); for (int k=0; k 

import java.util.*; public class DataSet { // Name associated with the data. String name; // The data is just a list of strings. LinkedList strings; // The toString() method for ease of printing. public String toString () { String s = name + ": "; if (strings == null) { return (s + "empty"); } for (int i=0; i 

# Smith Yes minister Seinfeld Cheers Frasier Simpsons # Jones Mad about you Seinfeld Frasier Cosby
In-Class Exercise 3: Download SetExample6.java, DataTool.java, DataSet.java, and the text file datafortwo. Then, do the following: Compile and execute to see how the data is retrieved and how intersection is computed. Draw the memory picture just before the println() in main) Use this largedataset which has a list of preferences for more than two people, and compute all the pairwise intersections. In-Class Exercise 3: Download SetExample6.java, DataTool.java, DataSet.java, and the text file datafortwo. Then, do the following: Compile and execute to see how the data is retrieved and how intersection is computed. Draw the memory picture just before the println() in main) Use this largedataset which has a list of preferences for more than two people, and compute all the pairwise intersections

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!