-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.java
131 lines (111 loc) · 3.37 KB
/
Book.java
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
/**
* @author lioraryepaz
* This class represents a book, which has a title, author, year of publication and different literary aspects.
*/
class Book {
/**
* The title of this book.
*/
final String title;
/**
* The name of the author of this book.
*/
final String author;
/**
* The year this book was published.
*/
final int yearOfPublication;
/**
* The comic value of this book.
*/
int comicValue;
/**
* The dramatic value of this book.
*/
int dramaticValue;
/**
* The educational value of this book.
*/
int educationalValue;
/**
* The id of the current borrowe of this book.
*/
int currentBorrowerId = -1;
/*----= Constructors =-----*/
/**
* Creates a new book with the given characteristic.
*
* @param bookTitle The title of the book.
* @param bookAuthor The name of the author of the book.
* @param bookYearOfPublication The year the book was published.
* @param bookComicValue The comic value of the book.
* @param bookDramaticValue The dramatic value of the book.
* @param bookEducationalValue The educational value of the book.
*/
Book(String bookTitle, String bookAuthor, int bookYearOfPublication, int bookComicValue, int bookDramaticValue,
int bookEducationalValue) {
title = bookTitle;
author = bookAuthor;
yearOfPublication = bookYearOfPublication;
comicValue = bookComicValue;
dramaticValue = bookDramaticValue;
educationalValue = bookEducationalValue;
}
/*----= Instance Methods =-----*/
/**
* Returns a string representation of the book, which is a sequence
* of the title, author, year of publication and the total literary value of the book, separated by
* commas, inclosed in square brackets.
*
* @return the String representation of this book.
*/
String stringRepresentation() {
return "[" + title + "," + author + "," + yearOfPublication + "," + getLiteraryValue() + "]";
}
/**
* @return the literary value of this book, which is defined as the sum of its comic value, its dramatic
* value and its educational value.
*/
int getLiteraryValue() {
return comicValue + dramaticValue + educationalValue;
}
/**
* @return the Comic value of this book
*/
int getComicValue() {
return comicValue;
}
/**
* @return the Dramatic value of this book
*/
int getDramaticValue() {
return dramaticValue;
}
/**
* @return the Educational value of this book
*/
int getEducationalValue() {
return educationalValue;
}
/**
* Sets the given id as the id of the current borrower of this book, -1 if no patron is currently borrowing
* it.
*
* @param borrowerId
*/
void setBorrowerId(int borrowerId) {
currentBorrowerId = borrowerId;
}
/**
* @return the id of the current borrower of this book.
*/
int getCurrentBorrowerId() {
return currentBorrowerId;
}
/**
* Marks this book as returned.
*/
void returnBook() {
currentBorrowerId = -1;
}
}