-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
134 lines (111 loc) · 3.5 KB
/
Book.java
File metadata and controls
134 lines (111 loc) · 3.5 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
package LibraryProject;
public class Book {
// Data members
private String title;
private String author1;
private String author2;
private String publisher;
private int yearPublication;
private String isbn;
private long accessionNum;
private LibMember issuedTo;
// Default constructor
public Book () {
title = "title";
author1 = "author1";
author2 = "author2";
publisher = "publisher";
isbn = "0";
yearPublication = 0;
accessionNum = 0;
issuedTo = null;
}
// Six-Parameter constructor
public Book (String title, String author1, String author2, String publisher, int yearPublication, String isbn, long accessionNum) {
// checks whether the isbn and accession number are correct
if (isbn.length() == 13 && accessionNum > 1000)
{
this.title = title;
this.author1 = author1;
this.author2 = author2;
this.publisher = publisher;
this.isbn = isbn;
this.yearPublication = yearPublication;
this.accessionNum = accessionNum;
issuedTo = null;
}
else
System.out.println("Invalid isbn or accessionNum");
}
// Set and Get methods for the data members
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor1() {
return author1;
}
public void setAuthor1(String author1) {
this.author1 = author1;
}
public String getAuthor2() {
return author2;
}
public void setAuthor2(String author2) {
this.author2 = author2;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public int getYearPublication() {
return yearPublication;
}
public void setYearPublication(int yearPublication) {
this.yearPublication = yearPublication;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
if (isbn.length() == 13)
this.isbn = isbn;
else
System.out.println("Invalid isbn");
}
public long getAccessionNum() {
return accessionNum;
}
public void setAccessionNum(long accessionNum) {
if (accessionNum>1000)
this.accessionNum = accessionNum;
else
System.out.println("Invalid accessionNum");
}
public LibMember getIssuedTo() {
return issuedTo;
}
public void setIssuedTo(LibMember issuedTo) {
this.issuedTo = issuedTo;
}
// ToString method: to return string equivalent of the book
@Override
public String toString() {
return ("Title: "+title+"\n " +
"Author 1: "+ author1+"\n " +
"Author 2: "+author2 +"\n " +
"Publisher: "+publisher +"\n " +
"Publication year: "+ yearPublication+"\n " +
"ISBN: "+isbn+"\n " +
"Accession Number: "+accessionNum +"\n " +
"Issued to: "+issuedTo.getCprNum());
}
// Equals method: to return true if this book is the same as the passed book
public boolean equals (Book b) {
return (b.accessionNum == accessionNum);
}
}