-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
94 lines (78 loc) · 2.07 KB
/
Book.java
File metadata and controls
94 lines (78 loc) · 2.07 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
import java.util.Arrays;
class Book {
private String id;
private String title;
private String author;
private boolean isAvailable;
private String gen;
private int timesOfBorrow;
public Book(String id, String title, String author, String gen) {
if (id.length() != 5) {
System.out.println("id must be d5 characters long");
}
this.id = id;
this.title = title;
this.author = author;
this.isAvailable = true;
this.gen = gen;
}
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public boolean isAvailable() {
return isAvailable;
}
public int getTimesOfBorrow() {
return timesOfBorrow;
}
public void setTitle(String title) {
this.title = title;
}
public void setTimesOfBorrow() {
timesOfBorrow++;
}
public String getGen() {
return gen;
}
public void setGen(String gen) {
this.gen = gen;
}
public void borrow() {
if (isAvailable) {
isAvailable = false;
} else {
System.out.println("Book is not available");
}
}
enum Genre {
FICTION,
FICTION_NON,
SCIENCE,
HISTORY,
FANTASY
}
public void capitalizeTitle(Book obj) {
String title = obj.getTitle();
String[] str = title.split(" ");
for (int i = 0; i < str.length; i++) {
String st = str[i];
char s = Character.toUpperCase(st.charAt(0));
String result = s + st.substring(1,st.length());
str[i] = result;
}
obj.setTitle(Arrays.toString(str));
}
public void returnBook() {
isAvailable = true;
}
public void printBookInfo() {
System.out.println("ID: " + id + ", Title: " + title + ", Author: " + author + ", Available: " + isAvailable +
"\nGenre: " + gen + "Times of borrow: " + timesOfBorrow);
}
}