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

i got the java code for library system management but i couldnot run it on eclip

ID: 3918653 • Letter: I

Question

i got the java code for library system management but i couldnot run it on eclipse can you help me , how to run it ? with explanation

package librarymanagementproject;

//Book class to workwith BookObject

public class Book {
   private int bookNumber;
   private String bookName;
   private boolean availability=true; // by this , we find whether the book is issued out or in Library

   public boolean isAvailability() {
       return availability;
   }

   public void setAvailability(boolean availability) {
       this.availability = availability;
   }

   public Book(int bookNumber,String name)
   {
       this.bookNumber=bookNumber;
       this.bookName=name;
   }

   public int getBookNumber() {
       return bookNumber;
   }

   public void setBookNumber(int bookNumber) {
       this.bookNumber = bookNumber;
   }

   public String getBookName() {
       return bookName;
   }

   public void setBookName(String bookName) {
       this.bookName = bookName;
   }

}

package librarymanagementproject;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class LMSImpl {

   static List<Book> books = new ArrayList<Book>();// List of books we provide
                                                   // at library

   public static void main(String[] args) {
       int choice;

       for (;;) {// infinite loop for menu

           System.out.println(" Library Management System");
           System.out.println("Press 1 to add Book");
           System.out.println("Press 2 to issue a book");
           System.out.println("Press 3 to return a book");
           System.out.println("Press 4 to print the books available");
           System.out.println("Press 5 to print the books Issued");
           System.out.println("Press 6 to exit >>");

           Scanner c = new Scanner(System.in);
           choice = c.nextInt();

           switch (choice) {
           case 1:
               addBook();
               break;
           case 2:
               issueBook();
               break;
           case 3:
               returnBook();
               break;
           case 4:
               printAvailableBooks();
               break;
           case 5:
               printIssuedBooks();
               break;
           case 6:
               System.exit(0);
           default:
               System.out.println("Invalid input");
               break;
           }

       }
   }

   // method to issue book
   private static void issueBook() {
       System.out.print("Enter Booknumber : ");
       Scanner c = new Scanner(System.in);
       int bookNumber = c.nextInt();
       for (Book book : books) {
           if (book.getBookNumber() == bookNumber) {
               book.setAvailability(false); // here we update availability to
                                               // false means its not available
                                               // right now
               System.out.println(">>>>" + book.getBookNumber() + " " + book.getBookName() + " issued, updated");
           }
       }
   }

   //method to return book
   private static void returnBook() {
       System.out.print("Enter Booknumber : ");
       Scanner c = new Scanner(System.in);
       int bookNumber = c.nextInt();
       for (Book book : books) {
           if (book.getBookNumber() == bookNumber) {
               book.setAvailability(true);// here we update status to true
                                           // means it is available right now
               System.out.println(">>>>" + book.getBookNumber() + " " + book.getBookName() + " returned, updated");
           }
       }
   }

   // add new books to library
   private static void addBook() {

       System.out.print("Enter Booknumber :");
       Scanner c = new Scanner(System.in);
       int bookNumber = c.nextInt();

       Scanner c1 = new Scanner(System.in);
       System.out.print("Enter Bookname :");
       String bookName = c1.nextLine();

       for (Book book : books) {
           if(book.getBookNumber()==bookNumber)
               System.out.print("book with this ID already with us..");
               break;
       }
       Book book = new Book(bookNumber, bookName);
       books.add(book);
       System.out.println(">>>>" + book.getBookNumber() + " " + book.getBookName() + " added, updated");

   }

   private static void deleteBook() { // delete unwanted books

       System.out.print("Enter Booknumber :");
       Scanner c = new Scanner(System.in);
       int bookNumber = c.nextInt();
       for (Book book : books) {
           if (book.getBookNumber() == bookNumber) {
               books.remove(book);
               System.out.println(">>>>" + book.getBookNumber() + " " + book.getBookName() + " removed, updated");
           }
       }

   }

   private static void printAvailableBooks() { // prints all available books in
                                               // library present
       System.out.println(">>>>printing all available books ");
       for (Book book : books) {

           if (book.isAvailability() == true) {
               System.out.println(book.getBookNumber() + " " + book.getBookName());
           }
       }
   }

   private static void printIssuedBooks() { // prints all books taken by
                                               // students
       System.out.println(">>>>printing all available books ");
       for (Book book : books) {

           if (book.isAvailability() == false) {
               System.out.println(book.getBookNumber() + " " + book.getBookName());
           }
       }
   }
}

Explanation / Answer

ScreenShot

Steps needed to run your application

         

package librarymanagementproject;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class LMSImpl {

   static List<Book> books = new ArrayList<Book>();// List of books we provide
                                                   // at library

   public static void main(String[] args) {
       int choice;

       for (;;) {// infinite loop for menu

           System.out.println(" Library Management System");
           System.out.println("Press 1 to add Book");
           System.out.println("Press 2 to issue a book");
           System.out.println("Press 3 to return a book");
           System.out.println("Press 4 to print the books available");
           System.out.println("Press 5 to print the books Issued");
           System.out.println("Press 6 to exit >>");

           Scanner c = new Scanner(System.in);
           choice = c.nextInt();

           switch (choice) {
           case 1:
               addBook();
               break;
           case 2:
               issueBook();
               break;
           case 3:
               returnBook();
               break;
           case 4:
               printAvailableBooks();
               break;
           case 5:
               printIssuedBooks();
               break;
           case 6:
               System.exit(0);
           default:
               System.out.println("Invalid input");
               break;
           }

       }
   }

   // method to issue book
   private static void issueBook() {
       System.out.print("Enter Booknumber : ");
       Scanner c = new Scanner(System.in);
       int bookNumber = c.nextInt();
       for (Book book : books) {
           if (book.getBookNumber() == bookNumber) {
               book.setAvailability(false); // here we update availability to
                                               // false means its not available
                                               // right now
               System.out.println(">>>>" + book.getBookNumber() + " " + book.getBookName() + " issued, updated");
           }
       }
   }

   //method to return book
   private static void returnBook() {
       System.out.print("Enter Booknumber : ");
       Scanner c = new Scanner(System.in);
       int bookNumber = c.nextInt();
       for (Book book : books) {
           if (book.getBookNumber() == bookNumber) {
               book.setAvailability(true);// here we update status to true
                                           // means it is available right now
               System.out.println(">>>>" + book.getBookNumber() + " " + book.getBookName() + " returned, updated");
           }
       }
   }

   // add new books to library
   private static void addBook() {

       System.out.print("Enter Booknumber :");
       Scanner c = new Scanner(System.in);
       int bookNumber = c.nextInt();

       Scanner c1 = new Scanner(System.in);
       System.out.print("Enter Bookname :");
       String bookName = c1.nextLine();

       for (Book book : books) {
           if(book.getBookNumber()==bookNumber)
               System.out.print("book with this ID already with us..");
               break;
       }
       Book book = new Book(bookNumber, bookName);
       books.add(book);
       System.out.println(">>>>" + book.getBookNumber() + " " + book.getBookName() + " added, updated");

   }

   private static void deleteBook() { // delete unwanted books

       System.out.print("Enter Booknumber :");
       Scanner c = new Scanner(System.in);
       int bookNumber = c.nextInt();
       for (Book book : books) {
           if (book.getBookNumber() == bookNumber) {
               books.remove(book);
               System.out.println(">>>>" + book.getBookNumber() + " " + book.getBookName() + " removed, updated");
           }
       }

   }

   private static void printAvailableBooks() { // prints all available books in
                                               // library present
       System.out.println(">>>>printing all available books ");
       for (Book book : books) {

           if (book.isAvailability() == true) {
               System.out.println(book.getBookNumber() + " " + book.getBookName());
           }
       }
   }

   private static void printIssuedBooks() { // prints all books taken by
                                               // students
       System.out.println(">>>>printing all available books ");
       for (Book book : books) {

           if (book.isAvailability() == false) {
               System.out.println(book.getBookNumber() + " " + book.getBookName());
           }
       }
   }
}

                 

package librarymanagementproject;

//Book class to workwith BookObject

public class Book {
   private int bookNumber;
   private String bookName;
   private boolean availability=true; // by this , we find whether the book is issued out or in Library

   public boolean isAvailability() {
       return availability;
   }

   public void setAvailability(boolean availability) {
       this.availability = availability;
   }

   public Book(int bookNumber,String name)
   {
       this.bookNumber=bookNumber;
       this.bookName=name;
   }

   public int getBookNumber() {
       return bookNumber;
   }

   public void setBookNumber(int bookNumber) {
       this.bookNumber = bookNumber;
   }

   public String getBookName() {
       return bookName;
   }

   public void setBookName(String bookName) {
       this.bookName = bookName;
   }

}