Skip to content

Commit 98b03f2

Browse files
Library Management System.java
1 parent a623ae2 commit 98b03f2

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Library Management System.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.*;
2+
3+
class Book {
4+
String title;
5+
boolean issued;
6+
7+
Book(String t) { this.title = t; this.issued = false; }
8+
}
9+
10+
public class Library {
11+
public static void main(String[] args) {
12+
ArrayList<Book> books = new ArrayList<>();
13+
Scanner sc = new Scanner(System.in);
14+
15+
books.add(new Book("Java"));
16+
books.add(new Book("Python"));
17+
books.add(new Book("C Programming"));
18+
19+
while (true) {
20+
System.out.println("1. Add 2. Issue 3. Return 4. List 5. Exit");
21+
int ch = sc.nextInt();
22+
sc.nextLine();
23+
24+
if (ch == 1) {
25+
System.out.print("Enter title: ");
26+
books.add(new Book(sc.nextLine()));
27+
}
28+
else if (ch == 2) {
29+
System.out.print("Enter title: ");
30+
String t = sc.nextLine();
31+
for (Book b : books)
32+
if (b.title.equalsIgnoreCase(t) && !b.issued) b.issued = true;
33+
}
34+
else if (ch == 3) {
35+
System.out.print("Enter title: ");
36+
String t = sc.nextLine();
37+
for (Book b : books)
38+
if (b.title.equalsIgnoreCase(t) && b.issued) b.issued = false;
39+
}
40+
else if (ch == 4) {
41+
for (Book b : books)
42+
System.out.println(b.title + " — " + (b.issued ? "Issued" : "Available"));
43+
}
44+
else break;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)