// pt 2
public void percentage() {
for (int i = 0; i < 4; i++) {
bPercent[i] = (int) Math.round(countB[i] * 100.0 / 70.0);
}
}
public String personalityType() {
String mbti = "";
mbti += (bPercent[0] > 50) ? "I" : (bPercent[0] < 50) ? "E" : "X";
mbti += (bPercent[1] > 50) ? "N" : (bPercent[1] < 50) ? "S" : "X";
mbti += (bPercent[2] > 50) ? "F" : (bPercent[2] < 50) ? "T" : "X";
mbti += (bPercent[3] > 50) ? "P" : (bPercent[3] < 50) ? "J" : "X";
return mbti;
}
public String[] result() {
String line1 = name + ":";
String line2 = " " + countA[0] + "A-" + countB[0] + "B " +
countA[1] + "A-" + countB[1] + "B " +
countA[2] + "A-" + countB[2] + "B " +
countA[3] + "A-" + countB[3] + "B";
String line3 = " [" + bPercent[0] + "%, " + bPercent[1] + "%, " +
bPercent[2] + "%, " + bPercent[3] + "%] = " + personalityType();
return new String[]{line1, line2, line3};
}
public static void main(String args[]) throws IOException {
Scanner detect = new Scanner(System.in);
System.out.println("Enter a file: ");
File file = new File(detect.next());
while (!file.exists()) {
System.out.println("File not found. Try again: ");
System.out.println("Enter a file: ");
file = new File(detect.next());
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
while (in.hasNextLine()) {
String name = in.nextLine();
String answers = in.nextLine();
Person p = new Person(name, answers);
for (String line : p.result()) {
out.println(line);
}
out.println();
}
in.close();
out.close();
}
}
}