-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathBook3.java
More file actions
104 lines (85 loc) · 2.24 KB
/
Book3.java
File metadata and controls
104 lines (85 loc) · 2.24 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
package src;
/**
* A class called circle is designed as shown in the following class diagram. It contains:
*
* 1) Two private instance variables: radius (of type double) and color (of type String),
* with default value of 1.0 and "red", respectively.
* 2) Two overloaded constructors;
* 3) Two public methods: getRadius() and getArea().
*
* The source codes for Circle is as follows:
*/
public class Book3 {
private String name;
private double price;
private Author[] authors = new Author[5];
private int numAuthors = 0;
private int qtyInStock = 0;
public Book3(String name, double price) {
this.name = name;
this.price = price;
}
public Book3(String name, double price, int qtyInStock) {
this.name = name;
this.price = price;
this.qtyInStock = qtyInStock;
}
public String getName() {
return this.name;
}
public double getPrice() {
return this.price;
}
public Author[] getAuthors() {
return this.authors;
}
public void setPrice(double price) {
this.price = price;
}
public int getQtyInStock() {
return this.qtyInStock;
}
public void setQtyInStock(int qtyInStock) {
this.qtyInStock = qtyInStock;
}
public void printAuthors() {
int authorNo = 0;
for (Author a : this.authors) {
if (a == null) {
continue;
}
System.out.println("("+(++authorNo)+") "+a);
}
}
public void addAuthor(Author author)
{
for (int i = 0; i < authors.length; i++)
{
if (authors[i] != null) {
continue;
}
authors[i] = author;
++numAuthors;
break;
}
}
public boolean removeAuthorByName(String authorName)
{
for (int i = 0; i < authors.length; i++)
{
if (authors[i] == null) {
continue;
}
if (! authorName.toUpperCase().equals(authors[i].getName().toUpperCase()) ) {
continue;
}
authors[i] = null;
--numAuthors;
return true;
}
return false;
}
public String toString() {
return "'" + name +"' by " + numAuthors + " authors";
}
}