I have this homework problem I\'m having trouble with. I can\'t get answers line
ID: 3536714 • Letter: I
Question
I have this homework problem I'm having trouble with. I can't get answers line correct for all the names. Please help I have been stuck on this for so long. Also the percent part is needs to be checked if it is correct too. My code: http://pastebin.com/3i9fPdwX The expected output: http://pastebin.com/5C1f2d2n Directions for assignment: http://pastebin.com/7cF4xgsQ text file: http://www.filedropper.com/personality Sorry if I am not able to answer/rate any of you soon. I will be back within 5 hrs or so.Explanation / Answer
the input file has lower and uppercase A, B & a, b as answers so you must check for both the cases that is what i have done and its working now.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class PersonalityTest {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("personality.txt");
System.out.println("** This program reports the results for Keirsey Personality Test **");
Scanner data = new Scanner(file);
char[] dimensionOne = {'E', 'I'};
char[] dimensionTwo = {'S', 'N'};
char[] dimensionThree = {'T', 'F'};
char[] dimensionFour = {'J', 'P'};
char[] rating = new char[4];
int columnoneACount;
int columnoneBCount;
int columnTwoThreeACount;
int columnTwoThreeBCount;
int columnSixSevenFiveACount;
int columnSixSevenFiveBCount;
int columnSixSevenAcount;
int columnSixSevenBcount;
String person;
String response;
char[][] responseArray;
if (file.exists()) {
while (data.hasNextLine()) {
person = data.nextLine();
response = data.nextLine();
responseArray = getResponses(response);
columnoneACount = getAcount(responseArray);
columnoneBCount = getBcount(responseArray);
columnTwoThreeACount = getATwocount(responseArray);
columnTwoThreeBCount = getBTwocount(responseArray);
columnSixSevenFiveACount = getAThreecount(responseArray);
columnSixSevenFiveBCount = getBThreecount(responseArray);
columnSixSevenAcount = getAFourAcount(responseArray);
columnSixSevenBcount = getBFourAcount(responseArray);
if (columnoneBCount * 100 / 10 < 50) {
rating[0] = dimensionOne[0];
} else {
rating[0] = dimensionOne[1];
}
if (columnTwoThreeBCount * 100 / 20 < 50) {
rating[1] = dimensionTwo[0];
} else {
rating[1] = dimensionTwo[1];
}
if (columnSixSevenFiveBCount * 100 / 20 < 50) {
rating[2] = dimensionThree[0];
} else {
rating[2] = dimensionThree[1];
}
if (columnSixSevenBcount * 100 / 20 < 50) {
rating[3] = dimensionFour[0];
} else {
rating[3] = dimensionFour[1];
}
if ((columnoneBCount * 100 / 10 == 50) ){
rating[0] = 'X';
}
if ((columnTwoThreeBCount * 100 / 20 ==50)){
rating[1] = 'X';
}
if ((columnSixSevenFiveBCount * 100 / 20 ==50)){
rating[2] = 'X';
}
if ((columnSixSevenBcount * 100 / 20 ==50 )){
rating[3] = 'X';
}
System.out.println();
System.out.println(person + ":");
System.out.println("answers: [" + columnoneACount + "A" + "-" + columnoneBCount + "B" + ", " + columnTwoThreeACount + "A" + "-" + columnTwoThreeBCount + "B" + ", " + columnSixSevenFiveACount + "A" + "-" + columnSixSevenFiveBCount + "B" + ", " + columnSixSevenAcount + "A" + "-" + columnSixSevenBcount + "B" + "]");
System.out.println("percent B: [" + columnoneBCount * 100 / 10 + ", " + columnTwoThreeBCount * 100 / 20 + ", " + columnSixSevenFiveBCount * 100 / 20 + ", " + columnSixSevenBcount * 100 / 20 + "]");
System.out.print("type: ");
for (int index = 0; index < 4; index++) {
System.out.print(rating[index]);
}
System.out.println();
}
}
}
private static char[][] getResponses(String response) {
char[][] temp = new char[10][7];
int index = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 7; j++) {
temp[i][j] = response.charAt(index);
index++;
}
}
return temp;
}
private static int getAcount(char[][] responseArray) {
int countA = 0;
for (int column = 0; column < 10; column++) {
if (responseArray[column][0] == 'A' || responseArray[column][0] == 'a') {
countA = countA + 1;
}
}
return countA;
}
private static int getBcount(char[][] responseArray) {
int countB = 0;
for (int column = 0; column < 10; column++) {
if (responseArray[column][0] == 'B' || responseArray[column][0] == 'b') {
countB = countB + 1;
}
}
return countB;
}
private static int getATwocount(char[][] responseArray) {
int countA = 0;
for (int column1 = 1; column1 < 3; column1++) {
for (int column = 0; column < 10; column++) {
if (responseArray[column][column1] == 'A' || responseArray[column][column1] == 'a') {
countA = countA + 1;
}
}
}
return countA;
}
private static int getBTwocount(char[][] responseArray) {
int countB = 0;
for (int column1 = 1; column1 < 3; column1++) {
for (int column = 0; column < 10; column++) {
if (responseArray[column][column1] == 'B' || responseArray[column][column1] == 'b') {
countB = countB + 1;
}
}
}
return countB;
}
private static int getAThreecount(char[][] responseArray) {
int countA = 0;
for (int column1 = 3; column1 < 5; column1++) {
for (int column = 0; column < 10; column++) {
if (responseArray[column][column1] == 'A' || responseArray[column][column1] == 'a') {
countA = countA + 1;
}
}
}
return countA;
}
private static int getBThreecount(char[][] responseArray) {
int countB = 0;
for (int column1 = 3; column1 < 5; column1++) {
for (int column = 0; column < 10; column++) {
if (responseArray[column][column1] == 'B' || responseArray[column][column1] == 'b') {
countB = countB + 1;
}
}
}
return countB;
}
private static int getAFourAcount(char[][] responseArray) {
int countB = 0;
for (int column1 = 5; column1 < 7; column1++) {
for (int column = 0; column < 10; column++) {
if (responseArray[column][column1] == 'A' || responseArray[column][column1] == 'a') {
countB = countB + 1;
}
}
}
return countB;
}
private static int getBFourAcount(char[][] responseArray) {
int countA = 0;
for (int column1 = 5; column1 < 7; column1++) {
for (int column = 0; column < 10; column++) {
if (responseArray[column][column1] == 'B' || responseArray[column][column1] == 'b') {
countA = countA + 1;
}
}
}
return countA;
}
}
output:
** This program reports the results for Keirsey Personality Test **
Betty Boop:
answers: [1A-9B, 17A-3B, 18A-2B, 18A-2B]
percent B: [90, 15, 10, 10]
type: ISTJ
Snoopy:
answers: [7A-3B, 11A-9B, 14A-6B, 6A-14B]
percent B: [30, 45, 30, 70]
type: ESTP
Bugs Bunny:
answers: [8A-2B, 11A-9B, 17A-3B, 9A-11B]
percent B: [20, 45, 15, 55]
type: ESTP
Daffy Duck:
answers: [0A-10B, 16A-1B, 16A-4B, 17A-1B]
percent B: [100, 5, 20, 5]
type: ISTJ
The frumious bandersnatch:
answers: [1A-6B, 1A-19B, 5A-15B, 4A-14B]
percent B: [60, 95, 75, 70]
type: INFP
Minnie Mouse:
answers: [3A-6B, 13A-5B, 13A-6B, 18A-1B]
percent B: [60, 25, 30, 5]
type: ISTJ
Luke Skywalker:
answers: [1A-8B, 7A-11B, 14A-5B, 15A-5B]
percent B: [80, 55, 25, 25]
type: INTJ
Han Solo:
answers: [2A-8B, 9A-9B, 11A-9B, 15A-5B]
percent B: [80, 45, 45, 25]
type: ISTJ
Princess Leia:
answers: [2A-8B, 10A-10B, 9A-9B, 19A-1B]
percent B: [80, 50, 45, 5]
type: IXTJ