-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkZone.java
More file actions
42 lines (36 loc) · 1.29 KB
/
WorkZone.java
File metadata and controls
42 lines (36 loc) · 1.29 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
import java.util.ArrayList;
import java.util.List;
public class WorkZone {
private List<Cilent> cilents;
private List<Miner> miners;
public WorkZone() {
this.cilents = new ArrayList<>();
this.miners = new ArrayList<>();
}
public void addCilent(Cilent cilent) {
cilents.add(cilent);
}
public void addMiner(Miner miner) {
miners.add(miner);
}
public void sendTransaction(Cilent sender, Cilent receiver, double amount) {
try {
boolean successful = sender.sendTransaction(receiver, amount);
if (successful) {
System.out.println("Transaction: " + sender.getId() + " sent " + amount + " bitcoins to " + receiver.getId());
} else {
System.out.println("Transaction failed: " + sender.getId() + " does not have sufficient balance.");
}
printBalances();
} catch (Exception e) {
System.out.println("Transaction failed due to an error: " + e.getMessage());
}
}
public void printBalances() {
System.out.println("Cilent Balances:");
for (Cilent cilent : cilents) {
System.out.println(cilent.getId() + ": " + cilent.getBalance() + " bitcoins");
}
System.out.println();
}
}