-
Notifications
You must be signed in to change notification settings - Fork 1
/
Book.java
143 lines (124 loc) · 3.96 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
132
133
134
135
136
137
138
139
140
141
142
143
/**AUTHOR: Laurence Toal
*CLASS: CS 230 Data Structures
*Final Project
*LAST MODIFIED: 15 December 2011
*CLASS DESCRIPTION: Contains all the information about a book object
**/
public class Book {
//instance variables
private String title;
private String author;
private String yearPublished;
private String branchLocation;
private String callNumber;
private String barcodeNumber;
private String status;
private boolean isOverdue;
private double overdueFee;
/**Constructs a book object given a title, author, year published,
*location, call number, barcode number, and status
**/
public Book(String title, String author, String yearPublished, String branchLocation, String callNumber, String barcodeNumber, String status) {
this.title = title;
this.author = author;
this.yearPublished = yearPublished;
this.branchLocation = branchLocation;
this.callNumber = callNumber;
this.barcodeNumber = barcodeNumber;
this.status = status;
this.isOverdue = false;
this.overdueFee = 0.0;
}
//getters
/**Returns the title of the book
*
*@return title a string that is the book's title
**/
public String getTitle() {
return title;
}
/**Returns the author of the book
*
*@return author a string that is the book's author
**/
public String getAuthor() {
return author;
}
/**Returns the publication year of the book
*
*@return yearPublished a string that is the book's publication year
**/
public String getYearPublished() {
return yearPublished;
}
/**Returns the branch location of the book
*
*@return branchLocation a string that is the book's location
**/
public String getBranchLocation() {
return branchLocation;
}
/**Returns the call number of the book
*
*@return callNumber a string that is the book's call number
**/
public String getCallNumber() {
return callNumber;
}
/**Returns the barcode number of the book
*
*@return barcodeNumber a string that is the book's barcode number
**/
public String getBarcodeNumber() {
return barcodeNumber;
}
/**Returns the status of the book
*
*@return status a string that is the book's status
**/
public String getStatus() {
return status;
}
//setters
/**Changes the location of a book
*
*@param newLocation the book's new location
**/
public void setBranchLocation(String newLocation) {
this.branchLocation = newLocation;
}
/**Changes the status of a book
*Can be "checked out", "available", "requested" or "in transit"
*
*@param newStatus the new status of the book
**/
public void setStatus(String newStatus) {
this.status = newStatus;
}
/**Marks a book as overdue by a number of days
*
*@param days an int representing how many days overdue the book is
*@return
**/
public void setOverdue() {
this.isOverdue = true;
}
/**Calculates the overdue fee on a book
*For simplicity's sake, assumes the fine is 50 cents
*no matter what book is overdue
*
*@param daysOverdue an int representing how many days overdue the book is
*@return overdueFee how much money is owed on the book
**/
public double calculateFee(int daysOverdue) {
this.overdueFee = daysOverdue*0.50;
return overdueFee;
}
/**Returns a string representation of the book
*
*@return a string represenaiton of the book
**/
public String toString() {
return "[Title: " + title + "\nAuthor: " + author + "\nYear Published: " + yearPublished + "\nLibrary: " + branchLocation + "\nStatus: " + status + "\nCall Number: " + callNumber + "\nBarcode: " + barcodeNumber + "\nOverdue? " + isOverdue + "\nFine: $" + overdueFee;
}
}