SHARE
TWEET

Untitled

a guest Nov 17th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package booklistwindow;
  2.  
  3. import booklistwindow.Book.BookCategory;
  4.  
  5. /**
  6.  * A collection of {@link Book}.
  7.  */
  8. public class BookStorage {
  9.  
  10.     private Book[] books = new Book[100];
  11.    
  12.  
  13.     public BookStorage() {
  14.      
  15.     }
  16.  
  17.     /**
  18.      * Initializes the book storage with some arbitrary book objects.
  19.      */
  20.     public void initBooks() {
  21.      
  22.         books[0] = new Book("hey", "no", 200 ,BookCategory.Design);
  23.         books[1] = new Book ("sdfsd", "sdf", 200, BookCategory.Database);
  24.         books[2] = new Book ("sdfsd", "sdf", 213, BookCategory.Programming);
  25.         books[3] = new Book ("sdfsd", "sdf", 345, BookCategory.Programming);
  26.         books[4] = new Book ("sdfsd", "sdf", 752, BookCategory.Programming);
  27.         books[5] = new Book ("sdfsd", "sdf", 234, BookCategory.Programming);
  28.         books[6] = new Book ("sdfsd", "sdf", 324, BookCategory.Programming);
  29.         books[7] = new Book ("sdfsd", "sdf", 592, BookCategory.Programming);
  30.         books[9] = new Book ("sdfsd", "sdf", 723, BookCategory.Programming);
  31.         books[10] = new Book ("sdfsd", "sdf", 849, BookCategory.Programming);
  32.        
  33.            }
  34.    
  35.  
  36.     /**
  37.      * Uses the given book to update the existing book with the same title.
  38.      */
  39.     public void update(Book book) {
  40.         // TODO Add your code here...
  41.     }
  42.  
  43.     /**
  44.      * Removes a book by title.
  45.      */
  46.     public void remove(String bookTitle) {
  47.         for(int i = 0; books.length < i; i++){
  48.             if(books[i].getTitle().equals(bookTitle)){
  49.                 books[i] = null;
  50.             }
  51.             else
  52.             {
  53.             System.out.println("");
  54.             }
  55.         }
  56.     }
  57.  
  58.     /**
  59.      * Adds a new book.
  60.      */
  61.     public void add(Book book) {
  62.        
  63.         if(book != null && books.length < 100){
  64.             int i = 10;
  65.             int y = i + 1;
  66.             books[y] = book;
  67.             i++;
  68.         }
  69.         else{
  70.             System.out.println("Book Storage is Full.");
  71.         }
  72.        
  73.     }
  74.  
  75.     /**
  76.      * Gets a book by title.
  77.      */
  78.     public Book getByTitle(String title) {
  79.         for(int k = 0; books.length < 100; k++){
  80.             if(books[k].getTitle().equals(title)){
  81.                 return books[k];
  82.             }
  83.             else{
  84.                 return null;
  85.             }
  86.        
  87.     }
  88.         return null;
  89.     }
  90.  
  91.     /**
  92.      * Searches for books whose title contains the keyword and returns them ordered by titles (in alphabet order).
  93.      */
  94.     public Book[] titleSearch(String keyword) {
  95.         for(int b = 0; books.length < 100; b++){
  96.             if(keyword.inde)
  97.         }
  98.         return new Book[0];
  99.     }
  100.  
  101.     /**
  102.      * Returns all books sorted by their titles (in alphabet order).
  103.      */
  104.     public Book[] getAll() {
  105.        
  106.         return new Book[0];
  107.     }
  108.  
  109.     /**
  110.      * Sorts an array of books by their titles in alphabet order.
  111.      */
  112.     private Book[] sortByTitle(Book[] bookArray) {
  113.         // TODO Add your code here...
  114.         return bookArray;
  115.     }
  116.  
  117. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top