-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
67 lines (53 loc) · 1.34 KB
/
Copy pathBook.java
File metadata and controls
67 lines (53 loc) · 1.34 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
package Books;
public class Book {
private Author[] authors;
private String name;
private int qty = 0;
private double price;
public Book (String newName, Author[] newAuthors, double newPrice) {
authors = newAuthors;
name = newName;
price = newPrice;
}
public Book (String newName, Author[] newAuthors, double newPrice, int newQty) {
authors = newAuthors;
name = newName;
price = newPrice;
qty = newQty;
}
public String getName() {
return name;
}
public Author[] getAuthors() {
return authors;
}
public String getAuthorNames() {
String result = "";
for(int i = 0; i < authors.length; i++) {
Author actual = authors[i];
result = result + actual.getName() + ",";
}
return result.substring(0,result.length() - 1);
}
public double getPrice() {
return price;
}
public void setPrice(double newPrice) {
price = newPrice;
}
public int getQty() {
return qty;
}
public void setQty(int newQty) {
qty = newQty;
}
public String toString() {
String part1 = "Book[name=" + name + ",author={";
String part2 = "},price=" + price + ",qty=" + qty + "]";
for(int i = 0; i < authors.length; i++) {
String x = authors[i].toString();
part1 = part1.concat(x+",");
}
return part1.substring(0, part1.length()-1) + part2;
}
}