-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryApplication.java
More file actions
71 lines (64 loc) · 3.02 KB
/
Copy pathLibraryApplication.java
File metadata and controls
71 lines (64 loc) · 3.02 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
import java.util.Scanner;
// Main application class for the library management system
public class LibraryApplication {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BookManager library = new BookManager();
// Add some initial books to the library for demonstration, now including a section
library.addBook("The Hobbit", "J.R.R. Tolkien", "Fantasy");
library.addBook("Dune", "Frank Herbert", "Science Fiction");
library.addBook("Foundation", "Isaac Asimov", "Science Fiction");
library.addBook("Harry Potter and The Prisoner of Azkaban", "J.K. Rowling", "Fantasy");
library.addBook("Gunahon Ka Devta", "Dharamvir Bharti", "Hindi Literature");
library.addBook("The Science of Interstellar", "Kip Thorne", "Science");
System.out.println();
//Menu driven loop
System.out.println("Library Management System Menu:");
while (true) {
// Print the menu options
System.out.println("Please choose an option:");
System.out.println("1. Show all books");
System.out.println("2. Add a new book");
System.out.println("3. Borrow a book");
System.out.println("4. Return a book");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
// Read the user's choice
int choice = scanner.nextInt();
scanner.nextLine();
// Handle the user's choice
switch (choice) {
case 1:
library.showAllBooks();
break;
case 2:
System.out.print("Enter the book title: ");
String title = scanner.nextLine();
System.out.print("Enter the book author: ");
String author = scanner.nextLine();
System.out.print("Enter the book section: ");
String section = scanner.nextLine();
// Call the updated addBook method
library.addBook(title, author, section);
break;
case 3:
System.out.print("Enter the title of the book to borrow: ");
String borrowTitle = scanner.nextLine();
library.borrowBook(borrowTitle);
break;
case 4:
System.out.print("Enter the title of the book to return: ");
String returnTitle = scanner.nextLine();
library.returnBook(returnTitle);
break;
case 5:
System.out.println("Thank you for using the library. Goodbye!");
scanner.close();
return; // Exit the main method, which ends the program
default:
System.out.println("Invalid choice. Please enter a number between 1 and 5.");
}
System.out.println();
}
}
}