-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestLibrarySystem.java
More file actions
150 lines (137 loc) · 4.5 KB
/
TestLibrarySystem.java
File metadata and controls
150 lines (137 loc) · 4.5 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
import java.util.Scanner;
import static java.lang.System.exit;
abstract class Item {
abstract void checkout();
abstract void returnItem();
abstract void displayDetails();
String title;
String author;
int year;
boolean available;
}
class Book extends Item{
String NameofBook;
int noofBooks=0;
String Publisher;
int issuedBooksCount=0;
void add(String Title, String Author, int year){
System.out.println("Added Book Successfully");
noofBooks++;
}
@Override
void checkout() {
System.out.println("Checked out Successfully");
noofBooks--;
issuedBooksCount++;
}
@Override
void returnItem() {
System.out.println("Book returned Successfully");
noofBooks++;
issuedBooksCount--;
}
@Override
void displayDetails() {
}
}
class DVD extends Item{
String NameofDVD;
int noofDVDs=0;
String Composer;
int issuedDVDCount=0;
void add(String NameofDVD, String composer, int noofDVDs,int issuedDVDCount){
System.out.println("Added DVD Successfully");
noofDVDs++;
}
@Override
void checkout() {
System.out.println("Checked out Successfully");
noofDVDs--;
issuedDVDCount++;
}
@Override
void returnItem() {
System.out.println("DVD returned Successfully");
noofDVDs++;
issuedDVDCount--;
}
@Override
void displayDetails() {
}
}
public class TestLibrarySystem
{
public static void main(String[] args){
String avail;
Book b=new Book();
DVD d=new DVD();
System.out.println("Welcome to the Library Management System!\n\n\n ");
System.out.println(" 1.Add Book \n" +
"2. Add DVD \n" +
"3. Display Available Items \n" +
"4. Check Out Item \n" +
"5. Return Item \n" +
"6. Exit \n\n ");
while(true) {
System.out.print("please enter your choice");
Scanner s = new Scanner(System.in);
int choice = s.nextInt();
switch (choice) {
case 1:
System.out.print("Enter book title:");
b.title = s.next();
System.out.print("Enter author:");
b.author = s.next();
System.out.print("Enter publication year:");
b.year = s.nextInt();
b.add(b.title, b.author, b.year);
break;
case 2:
System.out.print("Enter NameofDVD:");
d.NameofDVD = s.next();
System.out.print("Enter composer:");
d.Composer=s.next();
System.out.print("no of DVDs:");
d.noofDVDs = s.nextInt();
System.out.print("issued DVD count:");
d.issuedDVDCount= Integer.parseInt(s.next());
b.add(d.NameofDVD, String.valueOf(d.noofDVDs),d.issuedDVDCount);
break;
case 3:
System.out.println("Available Items:");
if(b.noofBooks>0){
b.available=true;
avail="yes";}
else{
b.available=false;
avail="No";
}
System.out.println("title:"+b.title+"author:"+b.author+"year:"+b.year+"available:"+avail);
break;
case 4:
System.out.println("Enter the title of the item you want to check out:");
b.title = s.next();
if(b.noofBooks>0)
{
//System.out.println("Item checkout Successfully");
b.noofBooks--;
b.issuedBooksCount++;
}
else {
System.out.println("Item checkout Successfully");
}
break;
case 5:
System.out.println("Enter the title of the item you want to return");
b.title = s.next();
b.noofBooks++;
b.issuedBooksCount--;
System.out.println("Item returned successfully!");
break;
case 6:
exit(0);
break;
}
}
}
}