Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package booklistwindow;
- import booklistwindow.Book.BookCategory;
- /**
- * A collection of {@link Book}.
- */
- public class BookStorage {
- private Book[] books = new Book[100];
- public BookStorage() {
- }
- /**
- * Initializes the book storage with some arbitrary book objects.
- */
- public void initBooks() {
- books[0] = new Book("hey", "no", 200 ,BookCategory.Design);
- books[1] = new Book ("sdfsd", "sdf", 200, BookCategory.Database);
- books[2] = new Book ("sdfsd", "sdf", 213, BookCategory.Programming);
- books[3] = new Book ("sdfsd", "sdf", 345, BookCategory.Programming);
- books[4] = new Book ("sdfsd", "sdf", 752, BookCategory.Programming);
- books[5] = new Book ("sdfsd", "sdf", 234, BookCategory.Programming);
- books[6] = new Book ("sdfsd", "sdf", 324, BookCategory.Programming);
- books[7] = new Book ("sdfsd", "sdf", 592, BookCategory.Programming);
- books[9] = new Book ("sdfsd", "sdf", 723, BookCategory.Programming);
- books[10] = new Book ("sdfsd", "sdf", 849, BookCategory.Programming);
- }
- /**
- * Uses the given book to update the existing book with the same title.
- */
- public void update(Book book) {
- // TODO Add your code here...
- }
- /**
- * Removes a book by title.
- */
- public void remove(String bookTitle) {
- for(int i = 0; books.length < i; i++){
- if(books[i].getTitle().equals(bookTitle)){
- books[i] = null;
- }
- else
- {
- System.out.println("");
- }
- }
- }
- /**
- * Adds a new book.
- */
- public void add(Book book) {
- if(book != null && books.length < 100){
- int i = 10;
- int y = i + 1;
- books[y] = book;
- i++;
- }
- else{
- System.out.println("Book Storage is Full.");
- }
- }
- /**
- * Gets a book by title.
- */
- public Book getByTitle(String title) {
- for(int k = 0; books.length < 100; k++){
- if(books[k].getTitle().equals(title)){
- return books[k];
- }
- else{
- return null;
- }
- }
- return null;
- }
- /**
- * Searches for books whose title contains the keyword and returns them ordered by titles (in alphabet order).
- */
- public Book[] titleSearch(String keyword) {
- for(int b = 0; books.length < 100; b++){
- if(keyword.inde)
- }
- return new Book[0];
- }
- /**
- * Returns all books sorted by their titles (in alphabet order).
- */
- public Book[] getAll() {
- return new Book[0];
- }
- /**
- * Sorts an array of books by their titles in alphabet order.
- */
- private Book[] sortByTitle(Book[] bookArray) {
- // TODO Add your code here...
- return bookArray;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement