-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemManager.java
More file actions
119 lines (97 loc) · 3.05 KB
/
SystemManager.java
File metadata and controls
119 lines (97 loc) · 3.05 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
package onlinestore;
import java.util.Arrays;
public class SystemManager {
private String systemName;
private Seller[] sellers;
private int amountSellers;
private Buyer[] buyers;
private int amountBuyers;
//Constructor
public SystemManager(String systemName) {
setSystemName(systemName);
this.amountSellers = 0;
this.amountBuyers = 0;
this.sellers = new Seller[2];
this.buyers = new Buyer[2];
}
public String getSystemName() {
return systemName;
}
public boolean setSystemName(String systemName) {
if (systemName == null || systemName.isEmpty()) {
return false;
}
this.systemName = systemName;
return true;
}
public boolean sellerNameExist(String sellerName) {
for (int i = 0; i < amountSellers; i++) {
if (sellerName.equals(sellers[i].getUserName())) {
return true;
}
}
return false;
}
private void largeArraySeller(){
if (amountSellers == sellers.length){
Seller[] newSellers = new Seller[sellers.length * 2];
for (int i = 0; i < sellers.length; i++) {
newSellers[i] = sellers[i];
}
sellers = newSellers;
}
}
public boolean addSeller(Seller seller) {
largeArraySeller();
sellers[amountSellers++] = new Seller(seller);
return true;
}
public boolean buyerNameExist(String buyerName) {
for (int i = 0; i < amountBuyers; i++) {
if (buyerName.equals(buyers[i].getUserName())) {
return true;
}
}
return false;
}
private void largeArrayBuyers(){
if (amountBuyers == buyers.length){
Buyer[] newBuyers = new Buyer[buyers.length * 2];
for (int i = 0; i < buyers.length; i++) {
newBuyers[i] = buyers[i];
}
buyers = newBuyers;
}
}
public boolean addBuyer(Buyer buyer) {
largeArrayBuyers();
buyers[amountBuyers++] = new Buyer(buyer);
return true;
}
public Seller[] getSellers() {
return sellers;
}
public Buyer[] getBuyers() {
return buyers;
}
public int getAmountSellers() {
return amountSellers;
}
public int getAmountBuyers() {
return amountBuyers;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof SystemManager)) {
return false;
}
SystemManager manager = (SystemManager) other;
return this.systemName.equals(manager.getSystemName()) && this.amountSellers == manager.getAmountSellers() &&
this.amountBuyers == manager.getAmountBuyers() && Arrays.equals(this.sellers, manager.getSellers()) &&
Arrays.equals(this.buyers, manager.getBuyers());
}
@Override
public String toString() {
return "Name: " + systemName + ", amountSellers: " + amountSellers + ", amountBuyers: " + amountBuyers;
}
}