-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyersBriggs.java
346 lines (328 loc) · 9.63 KB
/
MyersBriggs.java
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/* Name: Nicholas Keen
* Course: Computer Science I - CIS
* Section: 003
* Assignment: 11
*/
import java.util.*;
import java.io.*;
//This program reads and interprets
//a file as if it were the answers to
//a meyers briggs exam, then displays
//the results.
public class MyersBriggs {
//Reads the file through the args array
//creates a new file and calls the methods.
public static void main(String [] args)
throws FileNotFoundException{
File file = new File(args[0]);
PrintStream newFile = new PrintStream(fileName(args));
Scanner fileScanner = new Scanner(file);
meyersBriggs(fileScanner, newFile);
}
//Changes the extension of the file
//to .mb
public static String fileName(String [] args) {
String file = args[0];
int index = file.indexOf(".") + 1;
String newFile = file.substring(0, index) + "mb";
return newFile;
}
//Reads the lines and passes those lines
//to the name and data methods.
public static void meyersBriggs(Scanner fileScanner, PrintStream newFile) {
while(fileScanner.hasNextLine()) {
String line = fileScanner.nextLine();
String [] mb = new String [1];
Scanner lineScanner = new Scanner(line);
if(lineScanner.hasNext()){
lineScanner.next();
String nextLine = fileScanner.next();
for(int i = 0; i < mb.length; i++) {
mb[i] = name(line) + dim(nextLine) +
data(nextLine) + personality(nextLine);
newFile.println(mb[i]);
}
}
}
}
//Creates an array from the dim methods
//as well as prints out all of the data
//portions of the mb test.
public static String data(String nextLine) {
int [] percents = {dimOnePercent(nextLine),
dimTwoPercent(nextLine),
dimThreePercent(nextLine),
dimFourPercent(nextLine)};
String data = "[" + percents[0] + "%";
for(int i = 1; i < percents.length; i++) {
data = data + ", " + percents[i] + "%";
}
data = data + "] = ";
return data;
}
//Prints out the name of the
//individual who took the test.
public static String name(String line) {
String name = "";
if(line.contains(" ")) {
name = line + ":\r\n";
}
return name;
}
//and returns the percent of A responses for
//the first dimension of the mb test.
public static int dimOnePercent(String nextLine) {
char [] dimOne = {nextLine.charAt(0), nextLine.charAt(7),
nextLine.charAt(14), nextLine.charAt(21),
nextLine.charAt(28), nextLine.charAt(35),
nextLine.charAt(42), nextLine.charAt(49),
nextLine.charAt(56), nextLine.charAt(63)};
int a = 0;
int b = 0;
if(!nextLine.contains(" ")){
for(int i = 0; i < dimOne.length; i++) {
if(dimOne[i] == 'A'){
a++;
}else{
b++;
}
}
double math = (1.0*a/(a+b)*100);
int percent = (int) (math);
return percent;
}
return 0;
}
//Returns the number of responses i.e. A or B
//for the first dimension.
public static String dimOneAb(String nextLine) {
char [] dimOne = {nextLine.charAt(0), nextLine.charAt(7),
nextLine.charAt(14), nextLine.charAt(21),
nextLine.charAt(28), nextLine.charAt(35),
nextLine.charAt(42), nextLine.charAt(49),
nextLine.charAt(56), nextLine.charAt(63)};
int a = 0;
int b = 0;
String ab = "";
if(!nextLine.contains(" ")){
for(int i = 0; i < dimOne.length; i++) {
if(dimOne[i] == 'A'){
a++;
}else{
b++;
}
}
ab = a + "A-" + b + "B ";
}
return ab;
}
//Returns the percent of A responses for
//the second dimension of the mb test.
public static int dimTwoPercent(String nextLine) {
char [] dimTwo = {nextLine.charAt(1), nextLine.charAt(2),
nextLine.charAt(8), nextLine.charAt(9),
nextLine.charAt(15), nextLine.charAt(16),
nextLine.charAt(22), nextLine.charAt(23),
nextLine.charAt(29), nextLine.charAt(30),
nextLine.charAt(36), nextLine.charAt(37),
nextLine.charAt(43), nextLine.charAt(44),
nextLine.charAt(50), nextLine.charAt(51),
nextLine.charAt(57), nextLine.charAt(58),
nextLine.charAt(64), nextLine.charAt(65)};
int a = 0;
int b = 0;
if(!nextLine.contains(" ")){
for(int i = 0; i < dimTwo.length; i++) {
if(dimTwo[i] == 'A'){
a++;
}else{
b++;
}
}
double math = (1.0*a/(a+b)*100);
int percent = (int) (math);
return percent;
}
return 0;
}
//Returns the number of responses i.e. A or B
//for the second dimension.
public static String dimTwoAb(String nextLine) {
char [] dimTwo = {nextLine.charAt(1), nextLine.charAt(2),
nextLine.charAt(8), nextLine.charAt(9),
nextLine.charAt(15), nextLine.charAt(16),
nextLine.charAt(22), nextLine.charAt(23),
nextLine.charAt(29), nextLine.charAt(30),
nextLine.charAt(36), nextLine.charAt(37),
nextLine.charAt(43), nextLine.charAt(44),
nextLine.charAt(50),nextLine.charAt(51),
nextLine.charAt(57), nextLine.charAt(58),
nextLine.charAt(64), nextLine.charAt(65)};
int a = 0;
int b = 0;
String ab = "";
if(!nextLine.contains(" ")){
for(int i = 0; i < dimTwo.length; i++) {
if(dimTwo[i] == 'A'){
a++;
}else{
b++;
}
}
ab = a + "A-" + b + "B ";
}
return ab;
}
//Returns the percent of A responses for
//the third dimension of the mb test.
public static int dimThreePercent(String nextLine) {
char [] dimThree = {nextLine.charAt(3), nextLine.charAt(4),
nextLine.charAt(10), nextLine.charAt(11),
nextLine.charAt(17), nextLine.charAt(18),
nextLine.charAt(24), nextLine.charAt(25),
nextLine.charAt(31), nextLine.charAt(32),
nextLine.charAt(38), nextLine.charAt(39),
nextLine.charAt(45), nextLine.charAt(46),
nextLine.charAt(52),nextLine.charAt(53),
nextLine.charAt(59), nextLine.charAt(60),
nextLine.charAt(66), nextLine.charAt(67)};
int a = 0;
int b = 0;
if(!nextLine.contains(" ")){
for(int i = 0; i < dimThree.length; i++) {
if(dimThree[i] == 'A'){
a++;
}else{
b++;
}
}
double math = (1.0*a/(a+b)*100);
int percent = (int) (math);
return percent;
}
return 0;
}
//Returns the number of responses i.e. A or B
//for the third dimension.
public static String dimThreeAb(String nextLine) {
char [] dimThree = {nextLine.charAt(3), nextLine.charAt(4),
nextLine.charAt(10), nextLine.charAt(11),
nextLine.charAt(17), nextLine.charAt(18),
nextLine.charAt(24), nextLine.charAt(25),
nextLine.charAt(31), nextLine.charAt(32),
nextLine.charAt(38), nextLine.charAt(39),
nextLine.charAt(45), nextLine.charAt(46),
nextLine.charAt(52),nextLine.charAt(53),
nextLine.charAt(59), nextLine.charAt(60),
nextLine.charAt(66), nextLine.charAt(67)};
int a = 0;
int b = 0;
String ab = "";
if(!nextLine.contains(" ")){
for(int i = 0; i < dimThree.length; i++) {
if(dimThree[i] == 'A'){
a++;
}else{
b++;
}
}
ab = a + "A-" + b + "B ";
}
return ab;
}
//Returns the percent of A responses for
//the final dimension of the mb test.
public static int dimFourPercent(String nextLine) {
char [] dimFour = {nextLine.charAt(5), nextLine.charAt(6),
nextLine.charAt(12), nextLine.charAt(13),
nextLine.charAt(19), nextLine.charAt(20),
nextLine.charAt(26), nextLine.charAt(27),
nextLine.charAt(33), nextLine.charAt(34),
nextLine.charAt(40), nextLine.charAt(41),
nextLine.charAt(47), nextLine.charAt(48),
nextLine.charAt(54),nextLine.charAt(55),
nextLine.charAt(61), nextLine.charAt(62),
nextLine.charAt(68), nextLine.charAt(69)};
int a = 0;
int b = 0;
if(!nextLine.contains(" ")){
for(int i = 0; i < dimFour.length; i++) {
if(dimFour[i] == 'A'){
a++;
}else{
b++;
}
}
double math = (1.0*a/(a+b)*100);
int percent = (int) (math);
return percent;
}
return 0;
}
//Returns the number of responses i.e. A or B
//for the last dimension.
public static String dimFourAb(String nextLine) {
char [] dimFour = {nextLine.charAt(5), nextLine.charAt(6),
nextLine.charAt(12), nextLine.charAt(13),
nextLine.charAt(19), nextLine.charAt(20),
nextLine.charAt(26), nextLine.charAt(27),
nextLine.charAt(33), nextLine.charAt(34),
nextLine.charAt(40), nextLine.charAt(41),
nextLine.charAt(47), nextLine.charAt(48),
nextLine.charAt(54),nextLine.charAt(55),
nextLine.charAt(61), nextLine.charAt(62),
nextLine.charAt(68), nextLine.charAt(69)};
int a = 0;
int b = 0;
String ab = "";
if(!nextLine.contains(" ")){
for(int i = 0; i < dimFour.length; i++) {
if(dimFour[i] == 'A'){
a++;
}else{
b++;
}
}
ab = a + "A-" + b + "B \r\n";
}
return ab;
}
//Returns a String containing the values of
//of the dimAb methods.
public static String dim(String nextLine) {
String [] dim = {dimOneAb(nextLine), dimTwoAb(nextLine),
dimThreeAb(nextLine), dimFourAb(nextLine)};
String dimension = dim[0] + " " + dim[1] + " " +
dim[2] + " " + dim[3] ;
return dimension;
}
//Returns the personailty type.
public static String personality(String nextLine) {
int [] percents = {dimOnePercent(nextLine),
dimTwoPercent(nextLine),
dimThreePercent(nextLine),
dimFourPercent(nextLine)};
String first;
String second;
String third;
String fourth;
if(percents[0] >= 50) {
first = "I";
}else{
first = "E";
}if(percents[1] >= 50) {
second = "S";
}else{
second = "N";
}if(percents[2] >= 50) {
third = "T";
}else{
third = "F";
}if(percents[3] >= 50) {
fourth = "J";
}else{
fourth = "P";
}
return first + second + third + fourth;
}
}