Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write Java Code for: Add a new class, LibraryCollection. This class will have --

ID: 3684053 • Letter: W

Question

Write Java Code for:

Add a new class, LibraryCollection. This class will have --

a private instance variable that contains a collection of all your books

a private instance variable that contains a collection of all of your movies

a constructor that calls private methods to initialize your books and movies collection

a method to add a book to your books collection

a method to add a movie to your movies collection

a method to remove a book from your books collection

a method to remove a movie from your movies collection

a method to search for and return a book from your books collection by reference number

a method to search for and return a movie by reference number

a method (or methods) that search for books by author and/or title – or any combination of attributes. Should return an array list of books that meet the criteria. For example you want to search for any book written by Lee Childs.

a similar method to search for movies.

Finally, you need to write a class that can do the following by asking a user to enter data through the Blue J terminal window. You can invoke a method on this class to get started -- for example you might have a method public void returnABook() – that will ask you to enter the reference number of the book to be returned, then update the book’s status in your collection. In addition, this class should be able to do the following --

Add a book or movie through System in – that is the method should ask a user for the information on a book or a movie, read in the user responses and add a book or movie to your collection.

Allow a friend to borrow a book or movie.

Allow a friend to return a book or movie.

Print out all books and movies that are currently out on loan.

Delete a book or movie from your collection

Explanation / Answer

import java.util.Scanner;

public class Library

    {       

        private String location;

        private String openingHours;

        private Book book;

        private Map<Book,Integer> bookList = new HashMap<Book,Integer>();

        public Library(String location, String openingHours)

           {

            this.location = location;

            this.openingHours = openingHours;

        }

        public void addBook(Book book)

{       

           

            if (bookList.containsKey(book))

                bookList.put(book, bookList.get(book) + 1);

            else

                bookList.put(book, 1);

        }

        public String printOpeningHours()

{

            return openingHours;

        }

        public String printAddress()

{

            return location;

        }

        public void borrowBook(Book book)

{

            bookList.put(book, bookList.get(book) - 1);           

        }

        public void returnBook()

{

            bookList.put(book, bookList.get(book) + 1);

        }

        public String printAvailableBooks()

{

            ArrayList <String> available = new ArrayList();

            for (Book books: bookList.keySet())

                available.add(books.toString());

            return available.toString();

        }

        public boolean isBorrowed()

{

            int value = 0;

            for (Book bq: bookList.keySet())

{

                value = bookList.get(bq);

                if (value > 0)

                    return true;

            }

            return false;

        }

        public static void main(String[] args)

   {

            Scanner input = new Scanner(System.in);

            Library l1 = new Library("111 Your Street", "9am");

            l1.addBook(new Book("Test", "Author", "Test summary"));

            l1.addBook(new Book("Test2", "Author2", "Test summary2"));

            l1.addBook(new Book("Test3", "Author3", "Test summary3"));

            System.out.println(l1.printAvailableBooks());

            System.out.print("Choose book: ");

            Book book = (Book) input.next();

            borrowBook(book);

        }

   

Movie collection

import java.util.Scanner;

public class Movie

{

     String title;

      boolean borrowed;

      boolean rented;

      public Movie(String movieTitle)

{

          this.title = "Christmas in Kampala";

           

      }

      public void borrowed() {

     if(borrowed)

    rented = true;

     else

      rented = false;

      }

     public Boolean rented() {

         if(!rented)

      borrowed = true;

         else

          borrowed = false;

          return rented;

      }

      public void returned() {

     if(!rented)

      borrowed = false;

     else

      borrowed= true;

      }

      public boolean isBorrowed() {

       if(rented)

       rented = true;

       else

        rented = false;

         

              return borrowed;

      }

      public String getTitle() {

        return title;

      }

      public static void main(String[] arguments) {

          Movie example = new Movie("Christmas in Kampala");

System.out.println("Title (should be Christmas in Kampala): " + example.getTitle());

          System.out.println("Borrowed? (should be false): " + example.isBorrowed());

          example.rented();

          System.out.println("Borrowed? (should be true): " + example.isBorrowed());

          example.returned();

          System.out.println("Borrowed? (should be false): " + example.isBorrowed());

      }

Movie collection

  import java.util.*;  

import java.util.Scanner;

public class Movie

{

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote