-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlineLibrary.java
More file actions
76 lines (69 loc) · 1.87 KB
/
Copy pathOnlineLibrary.java
File metadata and controls
76 lines (69 loc) · 1.87 KB
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
72
73
74
75
import java.util.Scanner;
class library {
private Scanner sc = new Scanner(System.in);
private String [] books;
private String [] newbook;
public void addBook(String ...arr) {
if ( books == null ) {
this.books = new String[arr.length];
for(int i = 0; i<arr.length; i++) {
this.books[i] = arr[i];
}
}
else {
this.newbook = new String[books.length + arr.length];
for(int i = 0; i<books.length; i++) {
this.newbook[i] = books[i];
}
for(int i = 0; i<arr.length; i++) {
this.newbook[books.length + i] = arr[i];
}
this.books = new String[newbook.length];
for(int i = 0; i<newbook.length; i++) {
this.books[i] = newbook[i];
}
for(int i = 0; i<books.length; i++) {
newbook[i] = books[i].replace(" ", "");
newbook[i] = newbook[i].toLowerCase();
books[i] = newbook[i];
}
}
}
public void issueBook() {
System.out.print("Enter The Book You Want To Issue: ");
String bookName = sc.nextLine();
bookName = bookName.replace(" ", "");
bookName = bookName .toLowerCase();
for(int i = 0; i<books.length; i++) {
if(books[i] != null && books[i].equals(bookName)) {
books[i] = null;
System.out.println("Your Book is issued");
return;
}
}
}
public void returnBook() {
System.out.println("Enter The Book You Want To return: ");
String bookName = sc.nextLine();
bookName = bookName.replace(" ", "");
bookName = bookName.toLowerCase();
for(int i = 0; i<books.length; i++) {
if(books[i] == null) {
books[i] = bookName;
return;
}
}
}
public void showAvailableBooks() {
for(int i = 0; i<books.length; i++) {
System.out.println(books[i]);
}
}
}
public class OnlineLibrary {
public static void main (String[] args) {
library lms = new library();
//lms --> Library Management System.
//Here lms is an object. Use this object to call your methods from the custom class.
}
}