Skip to content

Instantly share code, notes, and snippets.

@stephaniekwoods
Created June 15, 2015 05:19
Show Gist options
  • Save stephaniekwoods/171546dd7dbbe47421e9 to your computer and use it in GitHub Desktop.
Save stephaniekwoods/171546dd7dbbe47421e9 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
public class AS4 {
public static final int DIMENSIONS = 4;
public static void main(String[] args)throws FileNotFoundException{
System.out.println("This program analyzes and reports results of The Keirsey Temperament Sorter.");
System.out.println();
Scanner myScanner = new Scanner(new File("personality.txt"));//scanner in
while (myScanner.hasNextLine()){
String name = myScanner.nextLine();
String answers = myScanner.nextLine().toUpperCase();
int[] A = arA(answers);
int[] B = arB(answers);
int[] percent = percent(B);
String[] type = type(percent, B);
printResults(name, answers, percent, type, A, B);//had trouble making sure the variables were called in the right order
//myScanner.close();//not sure if I actually need to close this?
}
}
public static void printResults(String name, String answers, int[] percent, String[]type, int[]A, int[]B){
System.out.print(name + ": \n");
System.out.print("[");
for (int c=0;c<A.length;c++){
System.out.print(A[c]+"-"+B[c]);
}
System.out.print("Answers: "+Arrays.toString(A) + "\n"+Arrays.toString(B) + "\n");
System.out.println("Percent B: " + Arrays.toString(percent));
String s="";//this is where the string goes and I'm not sure how to combine the methods
System.out.println("Type: "+Arrays.toString(type));
for(int t=0;t<type.length;t++){
s=type[t];
System.out.println(s);
}
}
public static int[] arA(String test){
int[] A = new int[DIMENSIONS];
for (int a=0; a<test.length();a++){
char t = test.charAt(a);
if (t=='A') {
if (a%7==0) {
A[0]++;
}
if (a%7==1||a%7==2){
A[1]++;
}
if (a%7==3||a%7==4){
A[2]++;
}
if (a%7==5||a%7==6){
A[3]++;
}
}
}
return A;
}
public static int[] arB(String test){
int[] B = new int[4];
for (int b=0; b<70; b++){
char t= test.charAt(b);
if (t=='B'){
if (b%7==0){
B[0]++;
}
if (b%7==1||b%7==2){
B[1]++;
}
if (b%7==3||b%7==4){
B[2]++;
}
if (b%7==5||b%7==6){
B[3]++;
}
}
}
return B;
}
public static int[] percent(int[] B){
int[] percent = new int[4];
percent[0]=100*B[0]/10;
for (int p=0;p<B.length; p++) {
percent[p]=100*B[p]/20;
}
for(int l=0;l<percent.length;l++){
double pp=percent[l];
percent[l]=(int)Math.round(pp);
}
return percent;
}
public static String[] type(int[] percentage, int[] countB) {
String[] type = new String[4];
for (int i = 0; i <= countB.length; i++) {
while (percentage[i] > 50) {
if (i == 0) {
type[1] = "I";
}
else if (i == 1) {
type[2] = "N";
}
else if (i == 2) {
type[3] = "F";
}
else {
type[4] = "P";
}
}
while ( percentage[i] < 50) {
if (i == 0 ) {
type[1] = "E";
}
else if (i == 1) {
type[2] = "S";
}
else if (i == 2) {
type[3] = "T";
}
else {
type[4] = "J";
}
}
}
return type;
}
}
@jsanders89
Copy link

Hello,

My name is Jonathan and I work with the introductory computer science courses at the University of Washington. This post contains solution code to a homework assignment that was adapted from one of our own.

This post's code is indexed by Google, enabling current students to easily find it and cheat on their assignments.

Would you please remove this post or make it secret in order to help us enforce our academic policy?

By removing this post, you would be removing a tool that our students could use in academic misconduct.

Thank you,
Jonathan Sanders
Intro Support, Computer Science & Engineering
University of Washington
jsanders@cs.washington.edu

More info on our course: http://courses.cs.washington.edu/courses/cse142/15au/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment