-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPractice_Online_Library.java
63 lines (52 loc) · 1.57 KB
/
Practice_Online_Library.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
package com.company;
class Library
{
int no_of_books;
String[] books;
public Library() {
this.books=new String[100];
this.no_of_books=0;
}
void addBook(String book){
this.books[no_of_books] = book;
no_of_books++;
System.out.println(book+ " has been added!");
}
void showAvailableBooks(){
System.out.println("Available Books are:");
for (String book : this.books) {
if (book == null){
continue;
}
System.out.println("* " + book);
}
}
void issueBook(String book){
for (int i=0;i<this.books.length;i++){
if (this.books[i].equals(book)){
System.out.println("The book has been issued!");
this.books[i] = null;
return;
}
}
System.out.println("This book does not exist");
}
void returnBook(String book){
addBook(book);
}
}
public class Practice_Online_Library {
public static void main(String[] args) {
// You have to implement a library using Java Class "Library"
// Methods: addBook, issueBook, returnBook, showAvailableBooks
// Properties: Array to store the available books,
// Array to store the issued books
Library l1=new Library();
l1.addBook("C++");
l1.addBook("Java");
l1.addBook("Python");
l1.issueBook("C++");
l1.returnBook("C++");
l1.showAvailableBooks();
}
}