-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainBanco.java
29 lines (23 loc) · 864 Bytes
/
MainBanco.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
package view;
import java.util.concurrent.Semaphore;
import controller.DepositoThread;
import controller.SaqueThread;
public class MainBanco {
public static void main(String[] args) {
Semaphore limitacaoDeposito = new Semaphore(1);
Semaphore limitacaoSaque = new Semaphore(1);
for (int i = 0; i < 20; i++) {
int tipo = (int) (Math.random() * 2);
int idConta = (int) (Math.random() * 10000);
double saldoConta = Math.round((Math.random() * 10000) * 100d) / 100d;
double valorTransacao = Math.round((Math.random() * 10000) * 100d) / 100d;
if (tipo == 0) {
DepositoThread deposito = new DepositoThread(idConta, saldoConta, valorTransacao, limitacaoSaque);
deposito.start();
} else if (tipo == 1) {
SaqueThread saque = new SaqueThread(idConta, saldoConta, valorTransacao, limitacaoDeposito);
saque.start();
}
}
}
}