-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextAnalysisRunner.java
More file actions
192 lines (123 loc) · 5.63 KB
/
Copy pathTextAnalysisRunner.java
File metadata and controls
192 lines (123 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* Name:
* Dr. Steinberg
* COP3330
* Programming Assignment 2
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;
public class TextAnalysisRunner {
public static void main(String[] args) {
System.out.println("Beginning Text Analysis...");
//file objects
File myObj = new File("sample1.txt"); //file object
File myObj2 = new File("sample2.txt"); //file object
File myObj3 = new File("macbethexcerpts.txt"); //file object
Random rand = new Random(0); //create new Random class object
//Scanner instances assign to null
Scanner fileio = null;
Scanner fileio2 = null;
Scanner fileio3 = null;
int num = rand.nextInt(96) + 1;
int num2 = rand.nextInt(114) + 1;
int num3 =rand.nextInt(128) + 1;
String [] data = new String [num]; //create string to store document 1
String [] data2 = new String [num2]; //create string to store document 2
String [] data3 = new String [num3]; //create string to store document 3
try
{
fileio = new Scanner(myObj);
fileio2 = new Scanner(myObj2);
fileio3 = new Scanner(myObj3);
}
catch (FileNotFoundException e) //do not worry about this just yet. We will learn about exception handling at the end
{
System.out.println("An error occurred.");
e.printStackTrace();
}
int x = 0;
while (fileio.hasNextLine() && x < num)
{
data[x] = fileio.nextLine();
++x;
}
x = 0;
while (fileio2.hasNextLine() && x < num2)
{
data2[x] = fileio2.nextLine();
++x;
}
x = 0;
while (fileio3.hasNextLine() && x < num3)
{
data3[x] = fileio3.nextLine();
++x;
}
System.out.println("Creating a TextAnalysis object text1 with limit " + num + ".");
TextAnalysis text1 = new TextAnalysis(num, data);
System.out.println("Here is the following text...");
System.out.println();
text1.display();
System.out.println();
System.out.println("Before any analysis is peformed for text1...");
text1.tableDisplay();
System.out.println();
System.out.println("Now Performing a Letter Analysis for text1...");
text1.letterAnalysis();
System.out.println("After letter analysis is peformed for text1...");
text1.tableDisplay();
System.out.println();
System.out.println("Now Performing a Word Analysis for text1...");
text1.wordAnalysis();
System.out.println("After letter Word Analysis (sentence limit) is peformed for text1...");
text1.wordAnalysis(99);
text1.tableDisplay();
fileio.close();
System.out.println();
System.out.println();
System.out.println("Creating a TextAnalysis object text2 with limit " + num2 + ".");
TextAnalysis text2 = new TextAnalysis(num2, data2);
System.out.println("Here is the following text...");
System.out.println();
text2.display();
System.out.println();
System.out.println("Before any analysis is peformed for text2...");
text2.tableDisplay();
System.out.println();
System.out.println("Now Performing a Letter Analysis for text2...");
text2.letterAnalysis();
System.out.println("After letter analysis is peformed for text2...");
text2.tableDisplay();
System.out.println();
System.out.println("Now Performing a Word Analysis for text2...");
text2.wordAnalysis();
System.out.println("After letter Word Analysis (sentence limit) is peformed for text2...");
text2.wordAnalysis(99);
text2.tableDisplay();
fileio2.close();
System.out.println();
System.out.println();
System.out.println("Creating a TextAnalysis object text3 with limit " + num3 + ".");
TextAnalysis text3 = new TextAnalysis(num3, data3);
System.out.println("Here is the following text...");
System.out.println();
text3.display();
System.out.println();
System.out.println("Before any analysis is peformed for text3...");
text3.tableDisplay();
System.out.println();
System.out.println("Now Performing a Letter Analysis for text3...");
text3.letterAnalysis();
System.out.println("After letter analysis is peformed for text3...");
text3.tableDisplay();
System.out.println();
System.out.println("Now Performing a Word Analysis for text3...");
text3.wordAnalysis();
System.out.println("After letter Word Analysis (sentence limit) is peformed for text3...");
text3.wordAnalysis(21);
text3.tableDisplay();
fileio3.close();
System.out.println("Ending Analysis...");
}
}