-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary_Management_System.java
More file actions
154 lines (154 loc) · 6 KB
/
Copy pathLibrary_Management_System.java
File metadata and controls
154 lines (154 loc) · 6 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
151
152
153
154
import java.util.Scanner;
import java.io.IOException;
class LibraryItem {
String name;
String type;
int id;
public void product(String name, int id,String type) {
this.name = name;
this.id = id;
this.type=type;
}
public int getfinedate() {
return 3;
}
public double calculatefine(int latedays) {
return latedays * 5.9;
}
public void show() {
System.out.println("\n----------------------------------------------");
System.out.println(" \n Reciept");
System.out.println("\n----------------------------------------------");
System.out.println("Type:" + this.type);
System.out.println("Title: " + this.name);
System.out.println("ID: " + this.id);
System.out.println("Borrowing Duration is "+getfinedate()+" Days");
}
}
class Books extends LibraryItem {
@Override
public int getfinedate() {
return 7;
}
@Override
public double calculatefine(int latedays) {
return latedays * 10.0;
}
}
class Journals extends LibraryItem {
@Override
public int getfinedate() {
return 3;
}
@Override
public double calculatefine(int latedays) {
return latedays * 15.0;
}
}
class DvD extends LibraryItem {
@Override
public int getfinedate() {
return 8;
}
@Override
public double calculatefine(int latedays) {
return latedays * 20.0;
}
}
class Magazines extends LibraryItem {
@Override
public int getfinedate() {
return 2;
}
@Override
public double calculatefine(int latedays) {
return latedays * 30.0;
}
}
public class Library_Management_System {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LibraryItem book = new Books();
LibraryItem journal = new Journals();
LibraryItem magzine = new Magazines();
LibraryItem dvd = new DvD();
while (true) {
System.out.println("\n----------------------------------------------");
System.out.println(" \n Main Menu");
System.out.println("\n----------------------------------------------");
System.out.print("\n1. Books\n2. Journals\n3. Magazines\n4. DVD\n0. Exit\nEnter:");
try {
int options = sc.nextInt();
sc.nextLine();
if (options == 0) {
System.out.println("Thanks For Using");
break;
}
switch (options) {
case 1:
book.type="BOOK";
System.out.print("Enter Name of the Book:");
book.name = sc.nextLine();
System.out.print("Enter Book ID:");
book.id = sc.nextInt();
System.out.println("Enter number of LateDays:");
int latedays = sc.nextInt();
double fine=book.calculatefine(latedays);
book.show();
System.out.print("Fine for "+latedays+" days = "+fine);
System.out.println("\nPress any Key to Continue");
System.in.read();
break;
case 2:
journal.type="JOURNAl";
System.out.print("Enter Name of the Journal:");
journal.name = sc.nextLine();
System.out.print("Enter Journal ID:");
journal.id = sc.nextInt();
System.out.print("Enter number of LateDays:");
int lateday = sc.nextInt();
double fines=journal.calculatefine(lateday);
journal.show();
System.out.print("Fine for "+lateday+" days = "+fines);
System.out.println("\nPress any Key to Continue");
System.in.read();
break;
case 3:
magzine.type="MAGZINE";
System.out.print("Enter Name of the Magzine:");
magzine.name = sc.nextLine();
System.out.println("Enter Magzine ID:");
magzine.id = sc.nextInt();
System.out.print("Enter number of LateDays:");
int maglateday = sc.nextInt();
double magfines=magzine.calculatefine(maglateday);
magzine.show();
System.out.print("Fine for "+maglateday+" days = "+magfines);
System.out.println("\nPress any Key to Continue");
System.in.read();
break;
case 4:
dvd.type="DVD";
System.out.print("Enter Name of the DVD:");
dvd.name = sc.nextLine();
System.out.print("Enter DVD ID:");
dvd.id = sc.nextInt();
System.out.print("Enter number of LateDays:");
int dvdlateday = sc.nextInt();
double dvdfines=dvd.calculatefine(dvdlateday);
dvd.show();
System.out.print("Fine for "+dvdlateday+" days = "+dvdfines);
System.out.println("\nPress any Key to Continue");
System.in.read();
break;
default:
System.out.println("Invalid Option");
}
} catch (Exception e) {
System.out.println("Invalid Input");
sc.nextLine();
}
}
sc.close();
}
}