In: Computer Science
Book
SerialNum : String -
Name: String –
PublishYear: int -
+ Book()
Book(String, String, String, int , int)+
+ setName(String) : void
+ setSerialNum(String) : void
+ setAuthor(String) : void
+ setEdition(int) : void
+ setYear(int) : void
+ getName():String
+ getAuthor():String
+ getYear(): int
+ getSerialNum(): String
+ getEdition():int
+ setAvailable() : void
+ setUnavailable(): void
checkAvailability(): boolean
-----------------------------------------------------------------------------------
Library
Name : String
Address: String
Static NUMBEROFBOOKS: int
BooksAtLibrray : ArrayList
LibraryIssues: TreeMap
Library()
Library(String, String)
addBook(Book): void
removeBook(Book) : Boolean
searchBookByName(Book) : Boolean
searchBookBySerialNumber(Book) : Boolean
checkBookAvailablity(Book): Boolean
createLibraryIssue(LibrrayIssue):Boolean
addLibraryIssue(LibraryIssue)
removeLibrrayIssue(LibrrayIssue):Boolean
searchLibrrayIssueByStuent(Student): List
searchLibraryIssuebyID(String IssueID):LibrrayIssue
searchLibraryIssueByBook(Book): LibraryIssue
--------------------------------------------------------------------------------------------------------------
Student
id : String
Name: String
Age : int
Student()
Student(String, String, int)
setName (String):void
SetAge(int):void
setId(String):void
getID():String
getName():String
getAge():int
---------------------------------------------------------------------------------------------------
LibraryIsuue
IssueID : String
borrower : Student
borrowedBook : Book
LibraryIssue()
LibraryIssue(String, Student , Book)
setIssueId(String):void
setBorrower(Student):void
setBorrowedBook(Book):void
getIssueID():String
getBorrowed():Student
getBorrowedBook():Book
----------------------------------------------------------------------------------------------------------
Librray
Main()
-----------------------------------------------------------------------------------------------------------------------------------------
Use the attached UML diagrams to build up your project classes
Make sure to put view for your project by Entering true data
You will need to add 5 books and 5 students and at least 3 LibraryIssues
LibraryIssues keeps track of the borrowed book
The librray uses all classes as mentioned in the UML diagram
You will need to check if book is available before borrowing it.
searchLibrrayIssueByStuent(Student): List
This method returns all book if borrowed by single student, as a student could borrow more than one book
Static NUMBEROFBOOKS: int
Each time you add a book the static variable is increased and Each time a book is removed so the static variable is decreased.
createLibraryIssue(LibraryIssue) : boolean
changed the Boolean variable status in book element to false and return false if book is not available
removeLibrrayIssue(LibraryIssue):Boolean
changed the Boolean variable status in book element to true and return false if book is available
Note
LibrrayIssue and Book in the class Library should be List or map
Do not use array as the size is not fixed
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
public class LibraryManagementSystem {
public static void main(String args[]){
Book b1 = new Book("101", "Harry Potter and the Goblet of Fire", "JK Rolling", 1998, 5);
Book b2 = new Book("102", "Harry Potter and the Soccer's Stone", "JK Rolling", 1996, 4);
Book b3 = new Book("103", " Autobiography of an Yogi", "James William", 2003, 7);
Book b4 = new Book("104", "Think and become Rich","James Gosling", 1999, 8);
Book b5 = new Book("105", "Julias Caesar", "William Shakespeare", 1887, 10);
Student s1 = new Student("Chritian Bale", "134", 21);
Student s2 = new Student("Julia Roberts", "135", 20);
Student s3 = new Student("Robert Downey", "138", 19);
Student s4 = new Student("Tom Hanks", "136", 22);
Student s5 = new Student("Irrfan Khan", "137", 21);
LibraryIssue l1= new LibraryIssue("Issue-101", s5, b1);
LibraryIssue l2= new LibraryIssue("Issue-102", s2, b3);
LibraryIssue l3= new LibraryIssue("Issue-103", s3, b4);
LibraryIssue l4= new LibraryIssue("Issue-104", s4, b5);
}
}
class Book{
private String SerialNum ;
private String Name;
private String Author;
private int PublishYear;
private int Edition;
private boolean Status;
Book(String SerialNum, String Name, String Author, int PublishYear,int Edition){
this.SerialNum = SerialNum;
this.Name =Name;
this.Author= Author;
this.PublishYear =PublishYear;
this.Edition =Edition;
}
public void setName(String Name){
this.Name=Name;
}
public void setSerialNum(String SerialNum){
this.SerialNum =SerialNum;
}
public void setAuthor(String Author){
this.Author =Author;
}
public void setPublisherYear(String PublisherYear){
this.PublisherYear =PublisherYear;
}
public void setEdition(String Edition){
this.Edition= Edition;
}
public int getEdition(){
return this.Edition;
}
public String getAuthor(){
return this.Author;
}
public String getName(){
return this.Name;
}
public String getSerialNum(){
return this.SerialNum;
}
public int getPublisherYear(){
return this.PublisherYear;
}
public void setAvailable(){
this.Status =true;
}
public void setUnAvailable(){
this.Status =false;
}
public boolean checkAvailability(){
return this.Status;
}
}
class Library{
private String Name;
private String Address;
private static int NUMBEROFBOOKS;
private ArrayList<Book> BooksAtLibrray = new ArrayList<>();
private ArrayList<LibraryIssue> LibraryIssues = new ArrayList<>();
Library(String Name, String Address){
this.Name =Name;
this.Address =Address;
}
public void addBook(Book book){
this.BooksAtLibrray.add(book);
NUMBEROFBOOKS++;
}
public boolean removeBook(Book book){
if(this.BooksAtLibrray.contains(book))
{
NUMBEROFBOOKS--;
return this.BooksAtLibrray.remove(book);
}
else{
return false;
}
}
public boolean searchBookByName(Book book){
if(!this.BooksAtLibrray.isEmpty())
{
for(Book myBook: this.BooksAtLibrray){
if(myBook.getName() == book.getName()){
return true;
}
}
return false;
}
else{
return false;
}
}
public boolean searchBookBySerialNumber(Book book) {
if(!this.BooksAtLibrray.isEmpty())
{
for(Book myBook: this.BooksAtLibrray){
if(myBook.getSerialNum() == book.getSerialNum()){
return true;
}
}
return false;
}
else{
return false;
}
}
public boolean checkBookAvailablity(Book book){
if(!this.BooksAtLibrray.isEmpty())
{
return book.checkAvailability();
}
else{
return false;
}
}
public boolean createLibraryIssue(LibrrayIssue libraryIssue){
if(libraryIssue.getBorrowedBook().checkAvailability()){
libraryIssue.getBorrowedBook.setUnAvailable();
return true;
}
else{
return false;
}
}
public void addLibraryIssue(LibraryIssue libraryIssue){
this.LibraryIssues.add(libraryIssue);
}
public boolean removeLibrrayIssue(LibrrayIssue libraryIssue){
if(libraryIssue.getBorrowedBook().checkAvailability()){
return false;
}
else{
libraryIssue.getBorrowedBook().setAvailable();
return true;
}
}
public List<Book> searchLibrrayIssueByStudent(Student student){
List<Book> mylist = new ArrayList<>();
for(LibraryIssue ls : this.LibraryIssues){
if(ls.getBorrowed().equals(student)){
mylist.add(ls.getBorrowedBook());
}
}
return mylist;
}
public LibraryIssue searchLibraryIssuebyID(String IssueID){
for(LibraryIssue ls : this.LibraryIssues){
if(ls.getIssueID() ==IssueID)
return ls;
}
return null;
}
public LibrrayIssue searchLibraryIssueByBook(Book book){
for(LibraryIssue ls : this.LibraryIssues){
if(ls.getBorrowedBook().equals(book))
return ls;
}
return null;
}
}
class Student{
private String id ;
private String Name;
private int Age ;
Student(String Name,String id, int Age){
this.Age =Age;
this.Name =Name;
this.id =id;
}
public void setName(String Name){
this.Name= Name;
}
public void setId(String id){
this.id = id;
}
public void setAge(String Age){
this.Age= Age;
}
public String getName(){
return this.Name;
}
public String getId(){
return this.id;
}
public int getAge(){
return this.Age;
}
}
class LibraryIssue{
private String IssueID ;
private Student borrower;
private Book borrowedBook;
LibraryIssue(String IssueID, Student student , Book book){
this.IssueID =IssueID;
this.borrower = student;
this.borrowedBook =book;
}
public void setIssueId(String issueID){
this.IssueID =issueID;
}
public void setBorrower(Student student){
this.borrower = student;
}
public void setBorrowedBook(Book book){
this.borrowedBook =book;
}
public String getIssueID(){
return this.IssueID;
}
public Student getBorrowed(){
return this.borrower;
}
public Book getBorrowedBook(){
return this.borrowedBook;
}
}