-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
139 lines (127 loc) · 4.63 KB
/
Main.java
File metadata and controls
139 lines (127 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
import java.util.*;
import java.lang.*;
import java.io.*;
interface Borrower
{
void checkin();
void checkout();
}
class Book
{
int bookID;
String title;
String author;
String booktype;
String status="Available";
String borroweduser="";
Book(int bookID, String title, String author, String booktype)
{
this.bookID=bookID;
this.title=title;
this.author=author;
this.booktype=booktype;
}
}
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
LinkedList<Book> lists=new LinkedList<>();
for(;;)
{
System.out.println("1. Add Reference Book\n2. Add Text Book\n3. Check-Out\n4. Check-In\n5. List Books\n6. Exit\n");
System.out.println("Enter your choice:");
int n=sc.nextInt();
String esc=sc.nextLine();
int id;
String title;
String author;
String username;
if(n==1)
{
System.out.println("Input ID, Title and Author");
id=sc.nextInt();
String buff=sc.nextLine();
title=sc.nextLine();
author=sc.nextLine();
Book b=new Book(id,title,author,"RefBook"); // RB: Reference Book
lists.add(b);
}
else if(n==2)
{
System.out.println("Input ID, Title and Author");
id=sc.nextInt();
String buff=sc.nextLine();
title=sc.nextLine();
author=sc.nextLine();
Book b=new Book(id,title,author,"TextBook"); // TB: Text Book
lists.add(b);
}
else if(n==3)
{
System.out.println("Input Book ID:");
id=sc.nextInt();
String buff=sc.nextLine();
for(Book b:lists)
{
if(b.bookID==id)
{
if(b.booktype.equals("RefBook"))
{
System.out.println("Cannot be borrowed");
break;
}
else
{
b.status="Borrowed";
username=sc.nextLine();
b.borroweduser=username;
}
}
}
}
else if(n==4)
{
System.out.println("Input Book ID:");
id=sc.nextInt();
for(Book b:lists)
{
if(b.bookID==id)
{
if(b.booktype.equals("RefBook"))
{
System.out.println("Invalid");
break;
}
else
{
b.status="Available";
}
}
}
}
else if(n==5)
{
for(Book b:lists)
{
if(b.booktype.equals("RefBook"))
{
System.out.println("ReferenceBook:"+b.bookID+":"+b.title+":"+b.author);
}
else
{
if(b.status.equals("Available"))
System.out.println("TextBook:"+b.bookID+":"+b.title+":"+b.author+":Available");
else
System.out.println("TextBook:"+b.bookID+":"+b.title+":"+b.author+":Borrowed by "+b.borroweduser);
}
}
}
else
{
break;
}
}
}
}