Initial submission due Tuesday, November 23, 11:59:59pm
This assignment will assess your mastery of the following objectives:
Scanner
and File
to read input from a file.PrintStream
and File
to write output to a file.Note: You do not need to read this section to complete the assessment, but it provides some helpful context that may make the assessment easier to understand.
In this assessment, you will be writing a program to process the results of a personality test known as the Keirsey Temperament Sorter. The Keirsey personality test involves answering 70 questions by choosing one of two answers. The Keirsey test measures four independent dimensions of personality:
Individuals are categorized as being on one side or the other of each of these dimensions. The corresponding letters are put together to form a personality type. For example, if you are an extrovert, intuitive, thinking, perceiving person then you are referred to as an ENTP. Usually the letter used is the first letter of the corresponding word, but notice that because the letter "I" is used for "Introvert", the letter "N" is used for "iNtuition."
If you are interested in taking the personality test yourself, you can do so in this survey. We will release a data file called bigdata.txt that includes data from students and staff in the class.
This program will process an input file containing the results of a personality test for a number of people and determine each person's Keirsey personality type. The program will begin by printing a short introduction, and then asking the user for an input file to read and an output file to print results to. The program will then read the given input file and process the responses to the personality test in that file, printing the results to the specified output file. Only the introduction and file prompting should be printed to the console.
The Keirsey test involves 70 questions, each of which can be answered either "A" or "B" (case-insensitively). Each question related to one of the four dimensions (see below), and each answer corresponds to one option or the other for that dimension. The "A" answers correspond to extrovert, sensation, thinking, and judging (the left-hand types in the list above), whereas the "B" answers correspond to introvert, intuition, feeling, and perceiving (the right-hand types in the list above). Questions can also be skipped, indicated by a response of "-".
The 70 questions in the Keirsey test are organized in ten groups of seven questions each. The first question in each group (i.e. questions 1, 8, 15, etc.) is related to the Extrovert/Introvert dimension. The next two questions in each group (questions 2 and 3, 9 and 10, 16 and 17, etc.) are related to Sensation/iNtuition. The next two questions (questions 4 and 5, 11 and 12, etc.) are related to Thinking/Feeling. The final two questions in each group (questions 6 and 7, 13 and 14, etc.) are related to Judging/Perceiving. Each person's responses will be provided in question order. That is, the first response is from question 1, the second response from question 2, and so on. As stated above, each response will be either "A" or "a" (for the "left-hand" response), "B" or "b" (for the "right-hand" response), or "-" (if the person skipped that question).
For each of the four dimensions, we determine the percentage of responses the person gave for that dimension that were "B" (rounded to the nearest integer). Smaller percentages indicate the person is closer to the "A" personality type for that dimension, while larger percentages indicate the person is closer to the "B" side. For each person in the input file, your program should output the person's name, the percentage of responses they gave for each dimension that were "B", and their overall personality type. See the sample output file below for the specific format.
For example, consider the first person in the sample input file personality.txt, named Betty Boop. This person's responses are as follows:
Dimension | # of A responses | # of B responses | %age B | Result |
---|---|---|---|---|
Extrovert/Introvert | 1 | 9 | 90% | I |
Sensation/iNtuition | 17 | 3 | 15% | S |
Thinking/Feeling | 18 | 2 | 10% | T |
Judging/Perceiving | 18 | 2 | 10% | J |
For each dimension, we count the total number of responses given, then determine the percentage of those responses that were "B". Based on this percentage, we assign the person to one side or the other of the dimension. If the percentage is less than 50, we assign them to the "A" side (the first option in each pair); if the percentage is greater than 50, the person is assigned to the "B" side (the second option in each pair). So, for example, Betty Boop has 90% "B" responses in the E/I dimension, so she is assigned to Introvert. On the other hand, she has only 15% "B" responses in the S/N dimension, so she is assigned to Sensing. It is also possible for a person to have exactly 50% "B" responses. In this case, the person is evenly split between the two sides of the dimension, and they are assigned "X" for that dimension. (See the sample input file for examples of this.)
Questions that were skipped (i.e. those that have a response of "-") are considered as neither A nor B responses and should not be included at all in the percentage calculation. So, for example, if a person skipped the first question on the test, they would only have 9 responses for the E/I dimension, rather than 10. If 6 of their responses were B, their percentage of B responses would be 6/9 ≈ 67%, not 60%. See the sample input and output files for more examples.
The input file will consist of pairs of lines, with each pair representing a single person. The first line in the pair will contain a person's name, which may include spaces. The second line will contain a sequence of 70 responses to the personality test questions. Each response will be one of "A", "B", "a", "b", or "-", and the responses will appear as a sequence of characters with no spaces. (See the sample input file for more details.)
You may assume that the input file is valid according to the format described above. Specifically, you may assume that:
As on previous assessments, you will likely want to approach the program one part at a time, rather than trying to write most or all of the program at once. We recommend the following approach:
The following suggestions and hints may help you be more successful on this assessment:
System.out
) while you are
developing your program.Arrays.toString
matches the format in which you should output arrays in your program.
Arrays.toString
method. Remember that this
method returns a String
, but does not print anything on its own—you will need to print the result
using one of the usual methods.Math.round
method, but this method returns a double
, so you will potentially need to cast the result to an
int
. You can do this using code like the following:
int roundedPercent = (int)Math.round(percentage);
Scanner
class and the
nextLine()
method.PrintStream
class as described in class and in the
textbook.Like all CSE 142 assessments, this assessment will be graded on all four dimensions defined in the syllabus. Be sure to adhere to the following guidelines:
To receive full credit, your program must include the following methods:
Each of these methods must perform only the tasks indicated, and must not contain any repeated logic.
Your program must also include at least two (2) other non-trivial methods besides main
besides these two. (Therefore, your program should have a total of at least four (4) non-trivial methods.) Each method
should perform a single, coherent task and not do too much work.
You are required to use arrays to store and process most of the data throughout your program. Specifically, you must use arrays to store the following data:
You must also use array traversals (via for
loops) to process the data and arrays and transform it from
one form to another. See the diagram below for the steps you should take to process and transform the
data throughout your program:
Data | Example |
---|---|
String (70 characters) | "BABAAAABAAAAAAABAAAABBAAAAAABAAAABABAABAAABABABAABAAAAAABAAAAAABAAAAAA" |
↓ | ↓ |
A/B counts (4 of each) | [1, 17, 18, 18], [9, 3, 2, 2] |
↓ | ↓ |
B Percentages (4) | [90, 15, 10, 10] |
↓ | ↓ |
Personality Type | "ISTJ" |
Because the Keirsey personality test assigns people on four dimensions, your program will likely include the number 4 in several places. To improve the readability of your code, you should include a class constant in your program to represent the number of dimensions (4). However, unlike previous constants, you should not expect to be able to change this value and have your program still function correctly. In this case, you will be using the constant purely for documentation and code quality purposes.
For this assessment, you are restricted to Java concepts covered in chapters 1 through 7 of the textbook, and you
MUST use arrays (see above). However you MAY NOT use two-dimensional arrays. You also
MAY NOT use the toCharArray
method in the Java String
class.
In addition to producing the desired behavior, your code should be well-written and meet all expectations described in the grading guidelines and the Code Quality Guide. For this assessment, pay particular attention to the following elements:
Your main
method in this program may have more code than it has in previous assessments. In particular,
you may include a limited amount of output and some control flow constructs in main
. However, your
main
method must remain a concise summary of your program's structure, and you must still utilize
methods to both capture structure and eliminate redundancy. In particular, you should not process a
line of input character-by-character in main
. Your program should utilize parameters and return values
effectively to produce a well-structured program as described above. Your methods should not accept
unnecessary or redundant parameters, and should not use parameters or return values inappropriately
(such as through "chaining").
You should use arrays appropriately throughout the assessment, including in the required places described
above. You must also reduce redundancy when processing arrays by using for
loops to traverse the array,
rather then writing separate code for each array element (referred to as "unrolling" the array). You should
also properly use arrays as parameters and return values. Remember that arrays use reference semantics,
meaning that when an array is passed as a parameter, its elements can be modified in the method and
the changes will be seen by the caller.
Your code should be properly indented, make good use of blank lines and other whitespace, and include
no lines longer than 100 characters. Your class, methods, variables, parameters and constants should all have
meaningful and descriptive names and follow the standard Java naming conventions. (e.g.
ClassName
, methodOrVariableName
,
CONSTANT_NAME
) See the Code Quality Guide for more information.
Your code should include a header comment at the start of your program, following the same format described in previous assessments. Your code should also include a comment at the beginning of each method that describes that method's behavior. Method comments should also explicitly name and describe all parameters to that method and describe the method's return value (if it has one). Comments should be written in your own words (i.e. not copied and pasted from this spec) and should not include implementation details (such as describing loops or expressions included in the code). See the Code Quality Guide for examples and more information.
If you find you are struggling with this assessment, make use of all the course resources that are available to you, such as:
Remember that, while you are encouraged to use all resources at your disposal, including your classmates, all work you submit must be your own. In particular, you should NEVER look at a solution to this assessment from another source (a classmate, a former student, an online repository, etc.). Please review the full policy in the syllabus for more details and ask the course staff if you are unclear on whether or not a resource is OK to use.
In addition to your code, you must submit answers to short reflection questions. These questions will help you think about what you learned, what you struggled with, and how you can improve next time. The questions are given in the "Reflection" slide in the Ed assessment.
Running and Submitting You can run your program by clicking the "Run" button in Ed. This will compile and execute your code and show you any errors, or the output of your program if it runs correctly. If you believe your output is correct, you can submit your work by clicking the "Mark" button in the Ed lesson. You will see the results of some automated tests along with tentative grades. This grade is not final until you have received feedback from your TA.
You may submit your work as often as you like until the deadline; we will always grade your most recent submission. Note the due date and time carefully—work submitted after the due time will not be accepted.