Advertisement
Guest User

Untitled

a guest
Jan 31st, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class jokes {
  5.  
  6. public static final int NUMBER_OF_JOKES = 48;
  7. public static final int RESPONSES_PER_JOKE = 10;
  8.  
  9. public static void main(String[] args) throws FileNotFoundException {
  10. int[] dataYes = new int[NUMBER_OF_JOKES];
  11. int[] dataNo = new int[NUMBER_OF_JOKES];
  12.  
  13. Scanner console = new Scanner(System.in);
  14. System.out.print("Enter filename: ");
  15. Scanner input = new Scanner(new File(console.next()));
  16.  
  17. while(input.hasNextLine()) {
  18. String line = input.nextLine();
  19. Scanner lineScan = new Scanner(line);
  20. String dataLine = lineScan.next();
  21. //System.out.println("Data before cleanUp: " + dataLine);
  22. dataLine = cleanUp(dataLine);
  23. System.out.println("Data after cleanUp: " + dataLine);
  24. // Remove the first character (ie, itemIndex)
  25. //dataLine = dataLine.replaceFirst(dataLine.substring(0, 1), "");
  26. while(dataLine.length() != 0) {
  27. int i = Character.getNumericValue(dataLine.charAt(0));
  28. // remove the jokeIndex
  29. dataLine = dataLine.replaceFirst(dataLine.substring(0, 1), "");
  30. if(dataLine.startsWith("yes")) {
  31. dataYes[i]++;
  32. dataLine = dataLine.replaceFirst(dataLine.substring(0, 3), "");
  33. } else {
  34. dataNo[i]++;
  35. dataLine = dataLine.replaceFirst(dataLine.substring(0, 2), "");
  36. } // end if
  37. } // end while
  38. } // end while
  39.  
  40. for(int i = 0; i < dataYes.length; i++) {
  41. System.out.println("Joke #" + (i + 1));
  42. System.out.print("Yes: " + dataYes[i] + "\tNo: " + dataNo[i]);
  43. System.out.println();
  44. System.out.println();
  45. }
  46.  
  47. } // end main
  48.  
  49. public static String cleanUp(String more) {
  50. more = more.substring(more.indexOf("jokeIndex"), more.length() - 1);
  51. // Replace everything not needed!
  52. more = more.replaceAll("\"", "");
  53. more = more.replaceAll("}],mturk:yes}", "");
  54. more = more.replaceAll("itemIndex", "");
  55. more = more.replaceAll("jokeIndex", "");
  56. more = more.replaceAll("responses", "");
  57. more = more.replaceAll("response", "");
  58. more = more.replaceAll(":", "");
  59. more = more.replaceAll("\\[", "");
  60. more = more.replaceAll("\\{", "");
  61. more = more.replaceAll("\\}", "");
  62. more = more.replaceAll(",", "");
  63. return more;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement