-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.java
More file actions
150 lines (129 loc) · 4.63 KB
/
Library.java
File metadata and controls
150 lines (129 loc) · 4.63 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package LibraryMangementSystem;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
public class Library {
Books ref = new Books();
public void displaybooks() {
System.out.println("***Displaying Books***");
System.out
.println("**** Civil Sevices Books Available In Library Are****");
ref.civilservicesBook();
System.out
.println("**** Mathematics Books Available In Library Are****");
ref.MathsBook();
System.out
.println("**** Literature Books Available In Library Are: ****");
ref.LiteratureBook();
System.out.println("**** Other Books Available In Library Are: ****");
ref.MiscellaneousBooks();
}
public void lendbooks(String name, String book) {
if (ref.list.contains(book) || ref.list1.contains(book)
|| ref.list2.contains(book) || ref.list3.contains(book)) {
HashMap<String, String> map = new HashMap<>();
map.put(name, book);
for (String str : map.keySet()) {
System.out.println(str + " you are borrowing " + map.values());
}
} else {
System.out.println("Book is not available");
}
}
public void addBook(ArrayList<String> addbook) {
ArrayList<String> finalList = new ArrayList<>();
finalList.addAll(ref.list);
finalList.addAll(ref.list1);
finalList.addAll(ref.list2);
finalList.addAll(ref.list3);
finalList.addAll(addbook);
System.out.println("****FINAL BOOK LIST****");
Iterator<String> finalitr = finalList.iterator();
while (finalitr.hasNext()) {
System.out.println(finalitr.next());
}
}
public void returnBook(String name, String book, Date bdate, Date rdate) {
System.out.println(name + " you borrow " + book + " on " + bdate);
System.out.println("you are returning " + book + " on " + rdate);
}
@SuppressWarnings("deprecation")
public void fine(Date bdate, Date rdate) {
int m1 = bdate.getMonth();
int y1 = bdate.getYear();
int m2 = rdate.getMonth();
int y2 = rdate.getYear();
int fine;
if (y2 == y1 || y1 > y2) {
if (m2 == m1 || m1 > m2) {
fine = 0;
} else
fine = (m1 - m2) * 500;
} else
fine = 10000;
System.out.println("You have to give : " + fine + " Rs/- as a fine ");
}
public void details(String NameOfStudent, String NameOfBook,
String NameOfUniversity, int uniqueId, int uniCode,
String Semester, String Branch, Date bdate, Date rdate) {
System.out.println("Name of Student :" + NameOfStudent);
System.out.println("Name of Book :" + NameOfBook);
System.out.println("Name of University :" + NameOfUniversity);
System.out.println("Id of Student :" + uniqueId);
System.out.println("University Code : " + uniCode);
System.out.println("Semester :" + Semester);
System.out.println("Name of branch :" + Branch);
returnBook(NameOfStudent, NameOfBook, bdate, rdate);
fine(bdate, rdate);
}
public static void main(String[] args) throws Exception {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
Library ref1 = new Library();
ref1.displaybooks();
;
while (true) {
System.out.println("Enter your name...");
String NameOfStudent = sc.nextLine();
System.out.println("Enter Book name....");
String NameOfBook = sc.nextLine();
System.out.println("Enter University name...");
String NameOfUniversity = sc.nextLine();
System.out.println("Enter Id of Student...");
int uniqueId = sc.nextInt();
System.out.println("Enter University code");
int uniCode = sc.nextInt();
System.out.println("Enter the semsester...");
String Semester = sc.next();
System.out.println("Enter the Branch");
String Branch = sc.next();
sc.nextLine();
ref1.lendbooks(NameOfStudent, NameOfBook);
System.out.println("Enter Books to add");
String AddBook = sc.nextLine();
ArrayList<String> Add = new ArrayList<>();
Add.add(AddBook);
ref1.addBook(Add);
System.out
.println("If you borrow and want to return the book give input as yes");
String input = sc.next();
if (input.endsWith("yes")) {
System.out.println("Date of borrowing the book");
String date = sc.next();
Date date2 = new SimpleDateFormat("dd/MM/yyyy/hh:mm:ss")
.parse(date);
System.out.println("Date of returning the book");
String Date1 = sc.next();
Date date1 = new SimpleDateFormat("dd/MM/yyyy/hh:mm:ss")
.parse(Date1);
ref1.details(NameOfStudent, NameOfBook, NameOfUniversity,
uniqueId, uniCode, Semester, Branch, date2, date1);
} else {
System.out.println("See you soon!!!!");
}
}
}
}