Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. public static void searchJournal() {
  2. Scanner keyboard = new Scanner(System.in);
  3. String call,title, organization, year;
  4. System.out.println("Enter Call #:");
  5. call = keyboard.nextLine();
  6. System.out.println("Enter Title:");
  7. title = keyboard.nextLine();
  8.  
  9.  
  10. //**********************YEAR START
  11. int count;
  12. String[] yr = new String[3];
  13. while (true) {
  14. int flag = 0;
  15. System.out.println("Enter Year:");
  16. year = keyboard.nextLine();
  17. String delimiters3 = "- ";
  18. StringTokenizer _year = new StringTokenizer(year,delimiters3,true);
  19.  
  20. count = _year.countTokens();
  21. for (int i = 0; i < count; i++) {
  22. yr[i] = _year.nextToken();
  23. if (stringIsInt(yr[i]) == false && yr[i].equals("-") == false) {
  24. System.out.println("Please input a numerical value for year");
  25. flag = 1;
  26.  
  27. }
  28. else if(stringIsInt(yr[i]) == true && (Integer.parseInt(yr[i]) > 9999 || Integer.parseInt(yr[i])<1000))
  29. {
  30. System.out.println("Value of year is out of rang(1000-9999!");
  31. continue;
  32. }
  33. }
  34. if(flag == 1)continue;
  35. break;
  36. }
  37.  
  38. if (call.equals("") && title.equals("")&& organization.equals("") && year.equals("")) {
  39. for (int i = 0; i < JournalDB.size(); i++) {
  40. Journal tempJournal = JournalDB.get(i);
  41. System.out.println(Journal.toString(tempJournal));
  42. }
  43. return;
  44. }
  45.  
  46. int[] numYearArray = new int[2];
  47. if(count == 1)
  48. {
  49. numYearArray[0] = 0;
  50. numYearArray[1] = Integer.parseInt(yr[0]);
  51. }
  52. else if(count == 0)
  53. {
  54. numYearArray[0] = 1000;
  55. numYearArray[1] = 9999;
  56. }
  57. else if ((yr[0] != null) && (yr[1].equals("-")) && (yr[2] != null)) {
  58. numYearArray[0] = Integer.parseInt(yr[0]);
  59. numYearArray[1] = Integer.parseInt(yr[2]);
  60. if(numYearArray[0] == numYearArray[1])
  61. {
  62. numYearArray[0] = 0;
  63. }
  64. }
  65.  
  66. else if ((yr[0].equals("-")) && (yr[1] != null)) {
  67. numYearArray[0] = 1000;
  68. numYearArray[1] = Integer.parseInt(yr[1]);
  69. }
  70. else if ((yr[0] != null) && (yr[1].equals("-"))) {
  71. numYearArray[0] = Integer.parseInt(yr[0]);
  72. numYearArray[1] = 9999;
  73. }
  74.  
  75.  
  76.  
  77.  
  78. //**********************YEAR END
  79.  
  80. String delimiters2 = " !";
  81. StringTokenizer _title = new StringTokenizer(title, delimiters2);
  82. StringTokenizer _organization = new StringTokenizer(organization, delimiters2);
  83. String[] organizationArray = fillArray(_organization);
  84.  
  85. String[] titleArray = fillArray(_title);
  86.  
  87.  
  88. int total = 0;
  89.  
  90. if(titleArray.length != 0)
  91. {
  92. total++;
  93. }
  94. if(organizationArray.length !=0 )
  95. {
  96. total++;
  97. }
  98. if (call.equals("") == false) {
  99. total++;
  100. }
  101. if (year.equals("") == false) {
  102. total++;
  103. }
  104. int found = 0;
  105. for (int i = 0; i < JournalDB.size(); i++) {
  106.  
  107. int match = 0;
  108. Journal tempJournal = JournalDB.get(i);
  109. String tempCall = tempJournal.getCall();
  110. String tempTitle = tempJournal.getTitle();
  111.  
  112. String tempYear = tempJournal.getYear();
  113.  
  114. StringTokenizer _tempTitle = new StringTokenizer(tempTitle,
  115. delimiters2);
  116. String tempOrganization = tempJournal.getOrganization();
  117. StringTokenizer _tempOrganization = new StringTokenizer(tempOrganization,
  118. delimiters2);
  119. if ((checkMatches(organizationArray, _organizationArray) >= organizationArray.length) && organizationArray.length != 0) {
  120. match++;
  121.  
  122.  
  123. }
  124. int tempYr = Integer.parseInt(tempYear);
  125.  
  126. String[] _titleArray = fillArray(_tempTitle);
  127. String[] _organizationArray = fillArray(_tempOrganization);
  128.  
  129. if (call.equalsIgnoreCase(tempCall)) {
  130. match++;
  131.  
  132. }
  133.  
  134.  
  135. if ((checkMatches(titleArray, _titleArray) >= titleArray.length) && titleArray.length != 0) {
  136. match++;
  137.  
  138.  
  139. }
  140.  
  141.  
  142. if(numYearArray[0] == 0)
  143. {
  144. if(numYearArray[1] == tempYr )
  145. {
  146. match++;
  147.  
  148.  
  149. }
  150. }
  151. else if(tempYr <= numYearArray[1] && tempYr >= numYearArray[0])
  152. {
  153. match++;
  154. if(year.equals("") == true)
  155. {
  156. match--;
  157. }
  158.  
  159.  
  160. }
  161.  
  162.  
  163. if (match == total) {
  164. System.out.println(Journal.toString(tempJournal));
  165. found = 1;
  166. }
  167.  
  168. }
  169. if(found == 0)
  170. {
  171. System.out.println("No Matches Found!");
  172. }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement