Advertisement
BorislavaYordanova

Book

May 1st, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package library;
  2.  
  3. import java.sql.Date;
  4.  
  5. public class Book implements Comparable<Book> {
  6.  
  7.     String title;
  8.     String author;
  9.     Date date;
  10.     String ISBN;
  11.     String format;
  12.     String publisher;
  13.     float price;
  14.     String[] keywords;
  15.     String[] inputArray;
  16.     String input;
  17.  
  18.     public Book(String title_param, String author_param, java.util.Date date_param, String ISBN_param,
  19.             String format_param, String publisher_param, float price_param, String keywords_param) {
  20.  
  21.         title = title_param;
  22.         author = author_param;
  23.         date = (Date) date_param;
  24.         ISBN = ISBN_param;
  25.         format = format_param;
  26.         publisher = publisher_param;
  27.         price = price_param;
  28.         keywords = keywords_param.split(",");
  29.  
  30.     }
  31.  
  32.     public void setUserInput(String userIn) {
  33.         input = userIn;
  34.     }
  35.  
  36.     private int getRelevance(String userInput) {
  37.         inputArray = userInput.split(",");
  38.         int num = 0;
  39.  
  40.         for (int i = 0; i != keywords.length; i++) {
  41.             String in = inputArray[i];
  42.  
  43.             for (int l = 0; l != keywords.length; l++) {
  44.                 if (in.equals(keywords[l]))
  45.                     num++;
  46.             }
  47.         }
  48.  
  49.         return num;
  50.     }
  51.  
  52.     public int compareTo(Book o) {
  53.         if (this.getRelevance(input) > o.getRelevance(input)) {
  54.             return 1;
  55.         } else if (this.getRelevance(input) < o.getRelevance(input)) {
  56.             return -1;
  57.         }
  58.  
  59.         return 0;
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement