Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Background Information: ?The Myers-Briggs personality test measures four compone

ID: 3632583 • Letter: B

Question

Background Information:
?The Myers-Briggs personality test measures four components of personality, each of which has two sides:
component 1: Extrovert vs. Introvert (E/I)
component 2: Sensation vs. iNtuition (S/N)
component 3: Thinking vs. Feeling (T/F)
component 4: Judging vs. Perceiving (J/P)
For each component, an individual is assigned to one side or the other based on their answers to a series of questions. Putting the corresponding letters together gives the person's personality type. For example, an introverted, intuitive, thinking, judging person is referred to as an INTJ.
Format of the Test?For the purposes of this assignment, we will assume that the test has 70 questions that are organized into 10 groups of seven questions, according to the following pattern:
The first question in each group (questions 1, 8, 15, etc.) is designed to measure component 1 (Extrovert/Introvert).
The next two questions in each group (questions 2 and 3, 9 and 10, 16 and 17, etc.) is designed to measure component 2 (Sensing/iNtuition).
The next two questions in each group (questions 4 and 5, 11 and 12, 18 and 19, etc.) is designed to measure component 3 (Thinking/Feeling).
The final two questions in each group (questions 6 and 7, 13 and 14, 20 and 21, etc.) is designed to measure component 4 (Judging/Perceiving).
Note that there are half as many questions for component 1 as there are for the other three components.
Each question in the test has two possible answers, which we will refer to as the "A" answer and the "B" answer. An "A" answer for a given question corresponds to the left-hand side of that question's component (E, S, T, or J), and a "B" answer corresponds to the right-hand side of that question's component (I, N, F, or P). For example, if a person answers "A" on question 9 -- which is a question for component 2 -- that question by itself suggests that she is a Sensing (S) person, since Sensing is the left-hand side of the Sensation/iNtuition component.
To determine a person's personality type, we count the number of "A" answers and the number of "B" answers for each component. If the person has more "A" answers for a given component, we assign him or her to the left-hand side of that component (E, S, T, J). If he has more "B" answers, we assign the person to the right-hand side of that component (I, N, F, P).
Your Program?Your task is to write a program that scores responses to the Myers-Briggs personality test and uses the results to determine a person's personality type. Your program should read an input file containing answers to the test questions from a number of different individuals, and it should create an output file that contains a summary of their answers and their resulting personality types.
Input File Format and Example Computation?The input file will contain a series of line pairs, one pair per person. The first line gives the person's name (possibly including spaces), and the second line gives the person's answers to the personality test as a string of 70 characters. For example, here is one entry from the file:
Luke Skywalker
BBBAAABBBBAABA-BAAAABBABBAAABBAABAAB-AAAAABBBABAABABA-ABBBABBABAA-AAAA
Note that his answers include four dashes, which indicate that he left those questions blank. You should ignore questions left blank when counting the answers.
Given the pattern for the questions that we stated above (see "Format of the Test"), Luke's answers map to the four personality components as follows:
1223344122334412233441223344122334412233441223344122334412233441223344
BBBAAABBBBAABA-BAAAABBABBAAABBAABAAB-AAAAABBBABAABABA-ABBBABBABAA-AAAA
where component 1 is E/I, component 2 is S/N, component 3 is T/F, and component 4 is J/P.
To determine Luke's personality type, we count the number of "A" answers and the number of "B" answers for each component. If he has more "A" answers for a given component, we assign him to the left-hand side of that component (E, S, T, J). If he has more "B" answers, we assign him to the right-hand side of that component (I, N, F, P). Here are his results:

component 1: 1 As, 8 Bs ==> Introvert (I)
component 2: 7 As, 11 Bs ==> iNtuition (N)
component 3: 14 As, 5 Bs ==> Thinking (T)
component 4: 15 As, 5 Bs ==> Judging (J)
Thus, Luke Skywalker is an INTJ.
Having computed these results, your program would write the following entry to the output file:
Luke Skywalker
1A-8B 7A-11B 14A-5B 15A-5B = INTJ

Getting started
Begin by downloading the following sample input file: answers.txt (link below)
http://cs-people.bu.edu/dgs/courses/cs111/assignments/ps6/answers.txt
Implementation guidelines: Using arrays?The program that you write should use arrays in a number of ways. In particular, you should:
Use two arrays to store the counts that you will compute when processing a given individual's answers:
one array that stores counts of the number of "A" answers for each personality component. After processing the results shown above for Luke Skywalker, this array would end up holding the values {1, 7, 14, 15}.
one array that stores counts of the number of "B" answers for each personality component. After processing the results shown above for Luke Skywalker, this array would end up holding the values {8, 11, 5, 5}.
Note that you should recreate these arrays for each individual, so that you will start over again with counts of 0. ?
Read in a person's string of answers ("ABA...") as a single String and then convert that string to an array of characters by using the toCharArray method. For example, if you have a variable answerString of type String, you can convert the string that answerString represents to an array of type char by doing the following: char[] answers = answerString.toCharArray();
?You can then process the individual answers by processing the characters in the array.
Optional: You may find it helpful to use the following two class-constant arrays when printing an individual's personality type (e.g., INTJ). // Letters for the left-hand side of each personality component.
public static final String[] LEFT_HAND_LETTERS = {"E", "S", "T", "J"};

// Letters for the right-hand side of each personality component.
public static final String[] RIGHT_HAND_LETTERS = {"I", "N", "F", "P"};
? If you do choose to use them, you should put them in your program in the same place that you declare the other class constants that your program will use (see below).

Other implementation guidelines
Put your program in a class named PersonalityScorer.
Your program should begin by asking for the names of the input and output files. Use a Scanner object to read from the input file, and a PrintStream object to write to the output file. You will not need to change the delimiters of the Scanner for this assignment.
Make sure that each entry in your output file follows the format shown above for Luke Skywalker. If a person has an equal number of As and Bs for a given component, use an X for that component. (For example, Han Solo should end up with an X for the second component.) You may assume that the input file follows the format given above, and that all of the answers are given as upper-case As, upper-case Bs, or dashes (-).
Use class constants to represent fixed values that appear in your program. For example, you could use a constant for the number of personality components (4) and for the number of groups of questions (10).
Use static methods to capture the structure of your program and to eliminate code duplication. You are required to have at least three useful static methods besides main. For full credit, the main method should not read anything from the input file or write anything to the output file; rather, all file-processing code should go in separate methods.
Testing your program?Here is a file containing the expected output file that your program should produce for the sample input file: expected_results.txt. (link below)
http://cs-people.bu.edu/dgs/courses/cs111/assignments/ps6/expected_results.txt

Suggested approach:
Stage 1: Start by writing code that just does the following: reads one person at a time from the input file, converts the person's answers to a char array (see implementation guideline b), and prints the name and the char array to the console (see the slide in the arrays lecture notes entitled "Printing an Array" for an easy way to do the printing).
Make sure that this initial method actually goes all the way through the input file, printing each person's info. Note that we've seen lots of methods that process an entire input file, so you should have plenty of models to draw from, including last week's problem set.
Stage 2: Then, once you know that you're actually reading in the entire file, write code that performs the counting -- processing the array of answers one element at a time and incrementing the appropriate elements of your two count arrays (see implementation guideline a).
Note that you will need to come up with a way of figuring out which element of the counts arrays you should modify for a given answer. Keep in mind the way that the questions are organized, as described above in the section labeled "Format of the Test". Hint: Consider using the modulus operator.
Test your answer-processing code by adding temporary printlns that print the contents of your two counts arrays.
Stage 3: Then, once your answer-processing code is working, add code that prints the results in the format required for the output file. Initially, you can just print these results to the console, and later you can change your println statements so that they write to the output file instead.
Stage 4: Finally, you can take care of other "finishing touches", such as making sure that you have three static methods besides main, perhaps by breaking out logical pieces of your current code into their own methods

Explanation / Answer

please rate - thanks

import java.io.*;
import java.util.*;
public class PersonalityScorer
{public static final int COMPONENTS=4;
public static void main(String[] args) throws FileNotFoundException
        {String filename;
        Scanner in=new Scanner(System.in);
        System.out.print("Enter the name of your input file: ");
        filename=in.nextLine();
        Scanner input=new Scanner(new File(filename));
        System.out.print("Enter the name of your output file: ");
        filename=in.nextLine();
        PrintStream out=new PrintStream(new File(filename));
        myersBriggs(input,out);
        }
public static void myersBriggs(Scanner input, PrintStream out)
       {int countAandB=0,i;
        String name,answers;
        int[] as=new int[COMPONENTS];
       int[] bs=new int[COMPONENTS];
        int[] percent=new int[COMPONENTS];
       while(input.hasNextLine())
             {for(i=0;i<COMPONENTS;i++)
                 {as[i]=0;
                bs[i]=0;
                countAandB=0;
                }
               name=input.nextLine();
            answers=input.nextLine();
            out.println(name+": ");          
            countAandB(answers,as,bs,out);
            getPercents(as,bs,percent,out);
            getType(percent,out);
            countAandB++;
           }
    }
    public static void countAandB(String answers,int[] as,int[] bs,PrintStream out)
        {int i,index;
        char letter;
        for(i=0;i<answers.length();i++)
             {letter=Character.toUpperCase(answers.charAt(i));
            if (letter!='-')
                   {index=(i%7+1)/2;
                    if(letter=='A')
                         as[index]++;
                else
                         bs[index]++;
                }
            }
        out.print("    ");
        for(i=0;i<COMPONENTS;i++)
                out.print(as[i]+"A-"+bs[i]+"B ");
         out.println();
    }
    public static void getPercents( int[] as,int[] bs,int percent[],PrintStream out)
         {int i,sum;
         for (i=0; i < COMPONENTS; i++)
            {sum=as[i]+bs[i];
            percent[i]=(int)Math.round(100.0*bs[i]/sum);
           }
        out.print("    ["+percent[0]+"%");
        for(i=1;i<COMPONENTS;i++)
                 out.print(", "+percent[i]+"%");
        out.print("]");
      }
    public static void getType(int[] percent,PrintStream out)
        {int i;
       
        out.print("=");
        for(i=0; i < COMPONENTS; i++)
              if(percent[i]<50)
                     out.print("ESTJ".charAt(i));
            else if(percent[i]==50)
                     out.print("X");
            else
                out.print("INFP".charAt(i));
         out.println();
            out.println();
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote