-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.java
More file actions
80 lines (69 loc) · 1.61 KB
/
library.java
File metadata and controls
80 lines (69 loc) · 1.61 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
import java.util.ArrayList;
abstract class LibraryItem
{
private String itemID;
private String title;
protected boolean isReserved;
LibraryItem(String id, String t)
{
itemID = id;
title = t;
}
void showDetails()
{
System.out.println("Item Details:\n");
System.out.println("Title: " + title);
System.out.println("Item ID: " + itemID);
System.out.println("Is Available: " + !isReserved);
}
String getTitle()
{
return title;
}
abstract void processLoan();
}
class Textbook extends LibraryItem
{
Textbook(String id, String t)
{
super(id,t);
}
void processLoan()
{
if(isReserved == true)
{
System.out.println(getTitle()+ " Cannot be checked out!");
}
else
{
System.out.println("Hardcopy reserved for 14 days!");
isReserved = true;
}
}
}
class ResearchPaper extends LibraryItem
{
ResearchPaper(String id, String t)
{
super(id,t);
}
void processLoan()
{
System.out.println("Generating Secure pdf link...");
}
}
public class library
{
public static void main(String[] args)
{
ArrayList<LibraryItem> L = new ArrayList<>();
Textbook book = new Textbook("B101", "Java Core");
L.add(book);
L.add(book);
L.add(new ResearchPaper("R99", "AI Ethics"));
for(int i = 0; i < L.size(); i++)
{
L.get(i).processLoan();
}
}
}