Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package library;
- import java.sql.Date;
- public class Book implements Comparable<Book> {
- String title;
- String author;
- Date date;
- String ISBN;
- String format;
- String publisher;
- float price;
- String[] keywords;
- String[] inputArray;
- String input;
- public Book(String title_param, String author_param, java.util.Date date_param, String ISBN_param,
- String format_param, String publisher_param, float price_param, String keywords_param) {
- title = title_param;
- author = author_param;
- date = (Date) date_param;
- ISBN = ISBN_param;
- format = format_param;
- publisher = publisher_param;
- price = price_param;
- keywords = keywords_param.split(",");
- }
- public void setUserInput(String userIn) {
- input = userIn;
- }
- private int getRelevance(String userInput) {
- inputArray = userInput.split(",");
- int num = 0;
- for (int i = 0; i != keywords.length; i++) {
- String in = inputArray[i];
- for (int l = 0; l != keywords.length; l++) {
- if (in.equals(keywords[l]))
- num++;
- }
- }
- return num;
- }
- public int compareTo(Book o) {
- if (this.getRelevance(input) > o.getRelevance(input)) {
- return 1;
- } else if (this.getRelevance(input) < o.getRelevance(input)) {
- return -1;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement