-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
170 lines (146 loc) · 3.51 KB
/
Book.java
File metadata and controls
170 lines (146 loc) · 3.51 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// -----------------------------------------------------
// Assignment 3
// Written by: André Assaad (40242006) and Adam Chami (40248165)
// -----------------------------------------------------
/**
* André Assaad (40242006) and Adam Chami (40248165)
* COMP249
* Assignment 3
* Due Date: Wednesday 29th March
*/
import java.io.Serializable;
/**
* The book class, which will be used to create book objects in part 2. Note that this class implements serializable
* @author Adam Chami and André Assaad
*
*/
public class Book implements Serializable{
private String title;
private String authors;
private double price;
private String isbn;
private String genre;
private int year;
/**
* The constructor for a book object. Each parameter is a field of the book's description.
* @param title title
* @param authors author names
* @param price book price
* @param isbn book's isbn
* @param genre book,s genre
* @param year release year
*/
public Book(String title, String authors, double price, String isbn, String genre, int year) {
this.title = title;
this.authors = authors;
this.price = price;
this.isbn = isbn;
this.genre = genre;
this.year = year;
}
/**
* getter for title.
* @return title
*/
public String getTitle() {
return title;
}
/**
* setter for title.
* @param title desired title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* getter for authors.
* @return author
*/
public String getAuthors() {
return authors;
}
/**
* setter for authors.
* @param authors desired author name(s)
*/
public void setAuthors(String authors) {
this.authors = authors;
}
/**
* getter for price.
* @return price price
*/
public double getPrice() {
return price;
}
/**
* setter for price.
* @param price desired price
*/
public void setPrice(double price) {
this.price = price;
}
/**
* getter for isbn.
* @return isbn isbn
*/
public String getIsbn() {
return isbn;
}
/**
* setter for isbn.
* @param isbn desired isbn
*/
public void setIsbn(String isbn) {
this.isbn = isbn;
}
/**
* getter for genre.
* @return genre genre
*/
public String getGenre() {
return genre;
}
/**
* setter for genre.
* @param genre desired genre
*/
public void setGenre(String genre) {
this.genre = genre;
}
/**
* getter for year.
* @return year year
*/
public int getYear() {
return year;
}
/**
* setter for year.
* @param year desired year
*/
public void setYear(int year) {
this.year = year;
}
/**
* toString method for a book class. Will be used to describe each book object.
*/
public String toString() {
return "Title: " + title + ", Authors: " + authors + ", Price: " + price + ", ISBN: " + isbn + ", Genre: "
+ genre + ", Year: " + year;
}
/**
* Equals method for the book class. Verifies if one book object is the same as another book object.
* @param book book to be compared.
* @return true if they are the same, false if not.
*/
public boolean equals(Book book) {
if (this == null || book==null || getClass() != book.getClass())
return false;
else if (title.equals(book.getTitle()) && authors.equals(book.getAuthors()) && price == book.getPrice()
&& isbn.equals(book.getIsbn()) && genre.equals(book.getGenre()) && year == book.getYear())
return true;
else
return false;
}
}