Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class jokes {
- public static final int NUMBER_OF_JOKES = 48;
- public static final int RESPONSES_PER_JOKE = 10;
- public static void main(String[] args) throws FileNotFoundException {
- int[] dataYes = new int[NUMBER_OF_JOKES];
- int[] dataNo = new int[NUMBER_OF_JOKES];
- Scanner console = new Scanner(System.in);
- System.out.print("Enter filename: ");
- Scanner input = new Scanner(new File(console.next()));
- while(input.hasNextLine()) {
- String line = input.nextLine();
- Scanner lineScan = new Scanner(line);
- String dataLine = lineScan.next();
- //System.out.println("Data before cleanUp: " + dataLine);
- dataLine = cleanUp(dataLine);
- System.out.println("Data after cleanUp: " + dataLine);
- // Remove the first character (ie, itemIndex)
- //dataLine = dataLine.replaceFirst(dataLine.substring(0, 1), "");
- while(dataLine.length() != 0) {
- int i = Character.getNumericValue(dataLine.charAt(0));
- // remove the jokeIndex
- dataLine = dataLine.replaceFirst(dataLine.substring(0, 1), "");
- if(dataLine.startsWith("yes")) {
- dataYes[i]++;
- dataLine = dataLine.replaceFirst(dataLine.substring(0, 3), "");
- } else {
- dataNo[i]++;
- dataLine = dataLine.replaceFirst(dataLine.substring(0, 2), "");
- } // end if
- } // end while
- } // end while
- for(int i = 0; i < dataYes.length; i++) {
- System.out.println("Joke #" + (i + 1));
- System.out.print("Yes: " + dataYes[i] + "\tNo: " + dataNo[i]);
- System.out.println();
- System.out.println();
- }
- } // end main
- public static String cleanUp(String more) {
- more = more.substring(more.indexOf("jokeIndex"), more.length() - 1);
- // Replace everything not needed!
- more = more.replaceAll("\"", "");
- more = more.replaceAll("}],mturk:yes}", "");
- more = more.replaceAll("itemIndex", "");
- more = more.replaceAll("jokeIndex", "");
- more = more.replaceAll("responses", "");
- more = more.replaceAll("response", "");
- more = more.replaceAll(":", "");
- more = more.replaceAll("\\[", "");
- more = more.replaceAll("\\{", "");
- more = more.replaceAll("\\}", "");
- more = more.replaceAll(",", "");
- return more;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement