Java Reference
In-Depth Information
69 i2++;
70 }
71 }
72 return result;
73 }
74
75 // post: explains program to user
76 public static void giveIntro() {
77 System.out.println("This program compares two text files");
78 System.out.println("and reports the number of words in");
79 System.out.println("common and the percent overlap.");
80 System.out.println();
81 }
82
83 // pre : common contains overlap between list1 and list2
84 // post: reports statistics about lists and their overlap
85 public static void reportResults(ArrayList<String> list1,
86 ArrayList<String> list2, ArrayList<String> common) {
87 System.out.println("file #1 words = " + list1.size());
88 System.out.println("file #2 words = " + list2.size());
89 System.out.println("common words = " + common.size());
90
91 double pct1 = 100.0 * common.size() / list1.size();
92 double pct2 = 100.0 * common.size() / list2.size();
93 System.out.println("% of file 1 in overlap = " + pct1);
94 System.out.println("% of file 2 in overlap = " + pct2);
95 }
96 }
The following program output is an execution of the program that compares the
texts of Shakespeare's Hamlet and King Lear:
This program compares two text files
and reports the number of words in
common and the percent overlap.
file #1 name? hamlet.txt
file #2 name? lear.txt
file #1 words = 4874
file #2 words = 4281
common words = 2108
% of file 1 in overlap = 43.24989741485433
% of file 2 in overlap = 49.24083158140621
Search WWH ::




Custom Search