Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void searchJournal() {
- Scanner keyboard = new Scanner(System.in);
- String call,title, organization, year;
- System.out.println("Enter Call #:");
- call = keyboard.nextLine();
- System.out.println("Enter Title:");
- title = keyboard.nextLine();
- //**********************YEAR START
- int count;
- String[] yr = new String[3];
- while (true) {
- int flag = 0;
- System.out.println("Enter Year:");
- year = keyboard.nextLine();
- String delimiters3 = "- ";
- StringTokenizer _year = new StringTokenizer(year,delimiters3,true);
- count = _year.countTokens();
- for (int i = 0; i < count; i++) {
- yr[i] = _year.nextToken();
- if (stringIsInt(yr[i]) == false && yr[i].equals("-") == false) {
- System.out.println("Please input a numerical value for year");
- flag = 1;
- }
- else if(stringIsInt(yr[i]) == true && (Integer.parseInt(yr[i]) > 9999 || Integer.parseInt(yr[i])<1000))
- {
- System.out.println("Value of year is out of rang(1000-9999!");
- continue;
- }
- }
- if(flag == 1)continue;
- break;
- }
- if (call.equals("") && title.equals("")&& organization.equals("") && year.equals("")) {
- for (int i = 0; i < JournalDB.size(); i++) {
- Journal tempJournal = JournalDB.get(i);
- System.out.println(Journal.toString(tempJournal));
- }
- return;
- }
- int[] numYearArray = new int[2];
- if(count == 1)
- {
- numYearArray[0] = 0;
- numYearArray[1] = Integer.parseInt(yr[0]);
- }
- else if(count == 0)
- {
- numYearArray[0] = 1000;
- numYearArray[1] = 9999;
- }
- else if ((yr[0] != null) && (yr[1].equals("-")) && (yr[2] != null)) {
- numYearArray[0] = Integer.parseInt(yr[0]);
- numYearArray[1] = Integer.parseInt(yr[2]);
- if(numYearArray[0] == numYearArray[1])
- {
- numYearArray[0] = 0;
- }
- }
- else if ((yr[0].equals("-")) && (yr[1] != null)) {
- numYearArray[0] = 1000;
- numYearArray[1] = Integer.parseInt(yr[1]);
- }
- else if ((yr[0] != null) && (yr[1].equals("-"))) {
- numYearArray[0] = Integer.parseInt(yr[0]);
- numYearArray[1] = 9999;
- }
- //**********************YEAR END
- String delimiters2 = " !";
- StringTokenizer _title = new StringTokenizer(title, delimiters2);
- StringTokenizer _organization = new StringTokenizer(organization, delimiters2);
- String[] organizationArray = fillArray(_organization);
- String[] titleArray = fillArray(_title);
- int total = 0;
- if(titleArray.length != 0)
- {
- total++;
- }
- if(organizationArray.length !=0 )
- {
- total++;
- }
- if (call.equals("") == false) {
- total++;
- }
- if (year.equals("") == false) {
- total++;
- }
- int found = 0;
- for (int i = 0; i < JournalDB.size(); i++) {
- int match = 0;
- Journal tempJournal = JournalDB.get(i);
- String tempCall = tempJournal.getCall();
- String tempTitle = tempJournal.getTitle();
- String tempYear = tempJournal.getYear();
- StringTokenizer _tempTitle = new StringTokenizer(tempTitle,
- delimiters2);
- String tempOrganization = tempJournal.getOrganization();
- StringTokenizer _tempOrganization = new StringTokenizer(tempOrganization,
- delimiters2);
- if ((checkMatches(organizationArray, _organizationArray) >= organizationArray.length) && organizationArray.length != 0) {
- match++;
- }
- int tempYr = Integer.parseInt(tempYear);
- String[] _titleArray = fillArray(_tempTitle);
- String[] _organizationArray = fillArray(_tempOrganization);
- if (call.equalsIgnoreCase(tempCall)) {
- match++;
- }
- if ((checkMatches(titleArray, _titleArray) >= titleArray.length) && titleArray.length != 0) {
- match++;
- }
- if(numYearArray[0] == 0)
- {
- if(numYearArray[1] == tempYr )
- {
- match++;
- }
- }
- else if(tempYr <= numYearArray[1] && tempYr >= numYearArray[0])
- {
- match++;
- if(year.equals("") == true)
- {
- match--;
- }
- }
- if (match == total) {
- System.out.println(Journal.toString(tempJournal));
- found = 1;
- }
- }
- if(found == 0)
- {
- System.out.println("No Matches Found!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement