Program needs to read from a file named MB.txt and output to the console, using
ID: 3551558 • Letter: P
Question
Program needs to read from a file named MB.txt and output to the console, using simple arrays.
Write a program MyerBriggsPeronsalityTest to score users' responses to the classic
Myers-Briggs personality test. Assume that the test has 70 questions that determine a person's personality in four
dimensions. Each question has two answer choices that we'll call the "A" and "B" answers. Questions are organized
into 10 groups of seven questions, with the following repeating pattern in each group:
? The first question in each group (questions 1, 8, 15, 22, etc.) tells whether the person is introverted or
extroverted.
? The next two questions (questions 2 and 3, 9 and 10, 16 and 17, 23 and 24, etc.) test whether the person is
guided by his or her senses or intuition.
? The next two questions (questions 4 and 5, 11 and 12, 18 and 19, 25 and 26, etc.) test whether the person
focuses on thinking or feeling.
? The final two questions in each group (questions 6 and 7, 13 and 14, 20 and 21, 27 and 28, etc.) test whether
the person prefers to judge or be guided by perception.
In other words, if we consider introversion/extroversion (I/E) to be dimension 1, sensing/intuition (S/N) to be
dimension 2, thinking/feeling (T/F) to be dimension 3, and judging/perception (J/P) to be dimension 4, the map of
questions to their respective dimensions would be:
1 2 3 4 5 6 7
Q: 1234567890123456789012345678901234567890123456789012345678901234567890
D: 1223344122334412233441223344122334412233441223344122334412233441223344
If less than 50% of a person's responses are B for a given personality dimension, the person's type for that dimension
should be the first if its two choices. If the person has 50% or more B responses, the person's type for that dimension
is the second choice. Your program should output each person's name, the number of A and B responses for each
dimension, the percentage of Bs in each dimension, and the overall personality type.
The file, MB.txt, contains the following data:
Snoopy
AABAAAAAAAAAAAABAAAABAAAAAAAAAAAABAAAABAAABABABAABAAAAAABAAAAAABAAAAAA
Charlie Brown
AAABBAABBABBBAABAAAABABABBAAAABABBBBABBBABAABABAABABAAABABAAABBAABABBB
Linus
AABBAABBBBBABAABBBBABABBABAAAABABBABABBAABAABABAABABBBBBBBAAAAAAABBBBB
Lucy
BABBAAABBBBAAABAAAAAABBBAABAAAAABBBAAABAAAAABABAAAABAABBBBAAABBAABABBB
Peppermint Patty
BBBBAAABBBBABBBAAAAAABBBAABAAAAABBBAAABAAAAABABAAAABAABBBBAAABBAABABBB
The output should be:
Snoopy:
6A-4B 17A-3B 18A-2B 18A-2B
[40%, 15%, 10%, 10%] = ISTJ
Charlie Brown:
7A-3B 11A-9B 9A-11B 10A-10B
[30%, 45%, 55%, 50%] = ISFP
Linus:
6A-4B 7A-13B 8A-12B 11A-9B
[40%, 65%, 60%, 45%] = INFJ
Lucy:
5A-5B 11A-9B 14A-6B 11A-9B
[50%, 45%, 30%, 45%] = ESTJ
Peppermint Patty:
5A-5B 10A-10B 14A-6B 9A-11B
[50%, 50%, 30%, 55%] = ENTP
what I have so far:
import java.io.*;
import java.util.*;
public class MyerBriggsPersonalityProfile {
public static void main( String [ ] args )
throws FileNotFoundException {
Scanner input = new Scanner( new File("MB.txt") );
final int NUM_GROUPS = 10; // The pattern, 1223344, is repeated in
final int NUM_IN_GROUP = 7; // the question sequence NUM_GROUPS times.
final char A = 'A';
final char B = 'B';
// this keeps track of # of Bs. for each dimension, I/E, S/N, T/F, J/P.
int[] dimensions = { 0, 0, 0, 0 };
final int IE = 0; // Introversion / Extroversion.
final int SN = 1; // Sensing / Intuition.
final int TF = 2; // Thinking / Feeling.
final int JP = 3; // Judging / Perception.
// symbols used to indicate type classes
final char[][] SYMBOLS = { { 'I', 'E' },
{ 'S', 'N' },
{ 'T', 'F' },
{ 'J', 'P' } };
while( input.hasNextLine() ) {
String name = input.nextLine();
String answers = input.nextLine();
// Clear entries for this individual
for( int i = 0; i < dimensions.length; i++ ) {
dimensions[ i ] = 0;
}
System.out.println( name + ":" );
// Calculate the number of Bs in each dimension.
// Report on this person's Myers-Briggs analysis.
// percentages conversion of questions with B as answer.
// Print Myers-Briggs type.
}
}
}
Explanation / Answer
//the code works perfect. CHeers
import java.io.*;
import java.util.*;
public class MyerBriggsPersonalityProfile {
public static void main( String [ ] args )
throws FileNotFoundException {
Scanner input = new Scanner( new File("MB.txt") );
final int NUM_GROUPS = 10; // The pattern, 1223344, is repeated in
final int NUM_IN_GROUP = 7; // the question sequence NUM_GROUPS times.
final char A = 'A';
final char B = 'B';
// this keeps track of # of Bs. for each dimension, I/E, S/N, T/F, J/P.
int[] dimensions = { 0, 0, 0, 0 };
final int IE = 0; // Introversion / Extroversion.
final int SN = 1; // Sensing / Intuition.
final int TF = 2; // Thinking / Feeling.
final int JP = 3; // Judging / Perception.
// symbols used to indicate type classes
final char[][] SYMBOLS = { { 'I', 'E' },
{ 'S', 'N' },
{ 'T', 'F' },
{ 'J', 'P' } };
while( input.hasNextLine() ) {
String name = input.nextLine();
String answers = input.nextLine();
// Clear entries for this individual
for( int i = 0; i < dimensions.length; i++ ) {
dimensions[ i ] = 0;
}
System.out.println( name + ":" );
// Calculate the number of Bs in each dimension.
int j=0;
for(int i=1;i<=10;i++)
{
if(answers.charAt(j)==B) {dimensions[ IE ]++;}
if(answers.charAt(j+1)==B) dimensions[ SN ]++;
if(answers.charAt(j+2)==B) dimensions[ SN ]++;
if(answers.charAt(j+3)==B) dimensions[ TF ]++;
if(answers.charAt(j+4)==B) dimensions[ TF ]++;
if(answers.charAt(j+5)==B) dimensions[ JP ]++;
if(answers.charAt(j+6)==B) dimensions[ JP ]++;
j=j+7;
}
// Report on this person's Myers-Briggs analysis.
System.out.print(10-dimensions[ IE ] + "A-"+ dimensions[ IE ]+ "B ");
System.out.print(20-dimensions[ SN ] + "A-"+ dimensions[ SN ]+ "B ");
System.out.print(20-dimensions[ TF ] + "A-"+ dimensions[ TF ]+ "B ");
System.out.println(20-dimensions[ JP ] + "A-"+ dimensions[ JP ]+ "B");
// percentages conversion of questions with B as answer.
float p1=((float)dimensions[ IE ])/10*100;
float p2=((float)dimensions[ SN ])/20*100;
float p3=((float)dimensions[ TF ])/20*100;
float p4=((float)dimensions[ JP ])/20*100;
char ch1,ch2,ch3,ch4;
if(p1<50) ch1=SYMBOLS[IE][0];
else ch1=SYMBOLS[IE][1];
if(p2<50) ch2=SYMBOLS[SN][0];
else ch2=SYMBOLS[SN][1];
if(p3<50) ch3=SYMBOLS[TF][0];
else ch3=SYMBOLS[TF][1];
if(p4<50) ch4=SYMBOLS[JP][0];
else ch4=SYMBOLS[JP][1];
// Print Myers-Briggs type.
System.out.println("[ "+p1+"%, "+p2+"%, "+p3+"%, "+p4+"%] = "+ch1+ch2+ch3+ch4);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.