-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibraryManagmentSystem.java
71 lines (62 loc) · 1.9 KB
/
LibraryManagmentSystem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.ArrayList;
/*
Create a library management system which is capable of issuing books to the students.
Book should have info like:
1. Book name
2. Book Author
3. Issued to
4. Issued on
User should be able to add books, return issued books, issue books
Assume that all the users are registered with their names in the central database
*/
class Book{
public String name, author;
public Book(String name, String author) {
this.name = name;
this.author = author;
}
@Override
public String toString() {
return "Book{" +
"name='" + name + '\'' +
", author='" + author + '\'' +
'}';
}
}
class MyLibrary{
public ArrayList<Book> books;
public MyLibrary(ArrayList<Book> books) {
this.books = books;
}
public void addBook(Book book){
System.out.println("The book has been added to the library");
this.books.add(book);
}
public void issueBook(Book book, String issued_to){
System.out.println("The book has been issued from the library to " + issued_to);
this.books.remove(book);
}
public void returnBook(Book b){
System.out.println("The book has been returned");
this.books.add(b);
}
}
public class LibraryManagmentSystem{
public static void main(String[] args) {
// Exercise 7 Solution
ArrayList<Book> bk = new ArrayList<>();
Book b1 = new Book("Algorithms", "CLRS");
bk.add(b1);
Book b2 = new Book("Algorithms2", "CLRS2");
bk.add(b2);
Book b3 = new Book("Algorithms3", "CLRS3");
bk.add(b3);
Book b4 = new Book("Algorithms4", "CLRS4");
bk.add(b4);
MyLibrary l = new MyLibrary(bk);
l.addBook(new Book("algo4", "myAuthor"));
System.out.println(l.books);
l.issueBook(b3, "Harry");
System.out.println(l.books);
}
}