-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
203 lines (177 loc) · 3.67 KB
/
Book.java
File metadata and controls
203 lines (177 loc) · 3.67 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//-----------------------------------------------------
// Assignment 3
// Part: 3 (Book class)
// Written by: Mira Alanzarouti 40195605
// Noor Kaddoura 40253572
//-----------------------------------------------------
package A3;
/**
* Book class that has the attributes to store its name, author that wrote it and its price
* also has isbn and genre of the book as a string and year
*/
public class Book {
protected String title;
protected String author;
protected double price;
protected long ISBN;
protected String genre;
protected int year;
/**
* default constructor
*/
public Book() {
super();
this.title = "";
this.author = "";
this.price = 0.0;
this.ISBN = 0;
this.genre = "";
this.year = 0;
}
/**
*
* parametrized constructor
* @param title
* @param author
* @param price
* @param ISBN
* @param genre
* @param year
*/
public Book(String title, String author, double price, long ISBN, String genre, int year) {
super();
this.title = title;
this.author = author;
this.price = price;
this.ISBN = ISBN;
this.genre = genre;
this.year = year;
}
/**
* Copy constructor
* @param book
*/
public Book(Book book) {
setTitle(book.title);
setAuthor(book.author);
setISBN(book.ISBN);
setGenre(book.genre);
setYear(book.year);
}
/**
* getter
* @return title of the Book
*/
public String getTitle() {
return title;
}
/**
* sets the title of the book
* @param title of type Stirng
*/
public void setTitle(String title) {
this.title = title;
}
/**
*
* @return the author of the book
*/
public String getAuthor() {
return author;
}
/**
* sets the author of the book
* @param author of type String
*/
public void setAuthor(String author) {
this.author = author;
}
/**
*
* @return the price of the book
*/
public double getPrice() {
return price;
}
/**
* sets the price of the book
* @param price of type double
*/
public void setPrice(double price) {
this.price = price;
}
/**
*
* @return the book ISBN
*/
public long getISBN() {
return ISBN;
}
/**
* sets the ISBN of the book
* @param iSBN of type long
*/
public void setISBN(long iSBN) {
ISBN = iSBN;
}
/**
* String
* @return the genre of the book
*/
public String getGenre() {
return genre;
}
/**
* sets the genre of type String
* @param genre of the book
*/
public void setGenre(String genre) {
this.genre = genre;
}
/**
*
* @return the year of publish
*/
public int getYear() {
return year;
}
/**
*
* @param year
*/
public void setYear(int year) {
this.year = year;
}
/**
* clones the object calling it
*/
public Book clone()
{
return new Book(this);
}
@Override
/**
* @return String representation of the book object
*/
public String toString() {
return "Title: " + title + ".\n Author: " + author + ".\n Price: " + price + ".\n ISBN: " + ISBN + ".\n Genre: " + genre
+ ".\n Year:" + year;
}
@Override
/**
* @param object to check if its equal to
* @return booleajn true if tehyre equal
*/
public boolean equals(Object inObj) {
if (this == inObj) {
return true;
}
if (inObj == null || getClass() != inObj.getClass()) {
return false;
}
Book other = (Book) inObj;
return this.title.equals(other.title) && this.author.equals(other.author)
&& Double.compare(this.price, other.price) == 0 && this.ISBN == other.ISBN
&& this.genre.equals(other.genre) && this.year == other.year;
}
}