#keirsey temperament sorter

1 messages · Page 1 of 1 (latest)

molten folio
#

hello! me and my classmates are having trouble with this one assignment : https://courses.cs.washington.edu/courses/cse142/21su/assessments/a7/

i will forward what i have so far (some from help of a friend) along with the test runner. ive been very confused and have spent hours...also as im writing this it just hit 2 am so perhaps my brain is not working very well aha

i would appreciate if anyone pointed out the mistakes and hint at what i should do... thank you

#

nevermind i dont think this server allows file upload

#

let me copy paste into sep msgs

#

code

#
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class Person {

    private String name;
    private String response;
    private int[] countA;
    private int[] countB;
    private int[] bPercent; // note: 10 e/i, 20 s/n, 20 t/f, 20 j/p

    // constructor with name and response
    public Person(String name, String response) {
        this.name = name;
        this.response = response;
        countA = new int[4];
        countB = new int[4];
        bPercent = new int[4];
    }

    public int dimensions(int i) {
        i = i % 7;
        if (i == 0) return 0;
        if (i == 1 || i == 2) return 1;
        if (i == 3 || i == 4) return 2;
        return 3;
    }

    public void storingInfo() {
        for (int i = 0; i < response.length(); i++) {
            char ans = response.charAt(i);
            int dim = dimensions(i);
            if (ans == 'a' || ans == 'A') countA[dim]++;
            if (ans == 'b' || ans == 'B') countB[dim]++;
        }
    }
#
// 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(); 
        }
    }
}
#

test runner

#
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class PersonalityTest {

    static Scanner in;

    @BeforeClass
    public static void load() throws FileNotFoundException {
        in = new Scanner(new File("output.txt"));
    }

    /**
     * Test of Betty output, of Personality file.
     */
    @Test
    public void aTestBettyAName() {
        System.out.println("Betty Test Name");
        String name = "Betty Boop:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of Betty output, of Personality file.
     */
    @Test
    public void aTestBettyBAns() {
        System.out.println("Betty Test Answers");
        String ans = "1A-9B 17A-3B 18A-2B 18A-2B";
        assertEquals(ans, in.nextLine().trim());
    }