-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControleTeleSena.java
More file actions
165 lines (137 loc) · 4.59 KB
/
ControleTeleSena.java
File metadata and controls
165 lines (137 loc) · 4.59 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import java.lang.Math;
public class ControleTeleSena {
private Pessoa[] participantes;
private Pessoa[] vencedores;
private int[] teleSenaSorteada;
private int quantTeleSenasRestantes;
private int numVencedores;
public ControleTeleSena() {
String[] nomes = {
"Thiago", "Frederico", "Ayanna", "Anderson", "Planadiscleuson", "Claudio", "Eliverton", "Asdrugbal",
"Michael", "Johnson", "Ismael", "Gabriel", "Terezinha", "Juscelina", "Grizelda", "Josuela",
"Leonardo", "Helena", "Fernandes", "Magda"
};
this.quantTeleSenasRestantes = 300;
this.numVencedores = 0;
this.participantes = new Pessoa[20];
this.vencedores = new Pessoa[20];
this.teleSenaSorteada = new int[61];
for(int i = 0; i < this.participantes.length; i++) {
// gerando numero de jogos aleatorios para cada pessoa com os nomes da array acima
this.participantes[i] = new Pessoa(nomes[i], ((int) (Math.random() * 15 + 1)));
}
}
// mesmo raciocinio de Pessoa.jogosTeleSena()
public void sorteioTeleSena() {
int[] tele = new int[61];
for (int j = 0; j < 25; j++) {
int aux;
do {
aux = (int) (Math.random() * 60 + 1);
} while (tele[aux] == 1);
tele[aux] = 1;
}
this.teleSenaSorteada = tele;
}
public boolean verificaVencedor() {
// percorrendo os participantes
for (Pessoa participante : this.participantes) {
// percorrerendo os jogos dos participantes
for (int j = 0; j < participante.getQuantJogos(); j++) {
int cont1 = 0;
int cont2 = 0;
// percorrendo os numeros de cada conjunto
for (int k = 0; k < 61; k++) {
// se a posicao do conjunto e da tele sena sorteada forem 1, soma +1 na quantidade de numeros iguais
if (participante.getTeleSenas()[j].getConjunto1()[k] == 1 && this.teleSenaSorteada[k] == 1) {
cont1++;
}
if (participante.getTeleSenas()[j].getConjunto2()[k] == 1 && this.teleSenaSorteada[k] == 1) {
cont2++;
}
}
/* Se um dos conjuntos tiver 25 posicoes iguais ao da tele sena, a pessoa é adicionada ao array
de vencedores. Logo, parte para o proximo participante do array. */
if (cont1 == 25 || cont2 == 25) {
this.vencedores[this.numVencedores++] = participante;
break;
}
}
}
return this.numVencedores > 0;
}
public void sorteioNovoNumero() {
int aux;
do {
aux = (int) (Math.random() * 60 + 1);
} while (this.teleSenaSorteada[aux] == 1);
this.teleSenaSorteada[aux] = 1;
}
public void atualizaQuantRestante() {
for (int i = 0; i < 20; i++) {
this.quantTeleSenasRestantes -= this.participantes[i].getQuantJogos();
}
}
public double calculaValorTotal() {
double valorTotal = 0;
for (Pessoa participante : this.participantes) {
valorTotal += participante.getValorGasto();
}
return valorTotal;
}
public double valorPremiacao() {
// premio e 80% do valor total dividido igualmente entre os vencedores
double premio = (calculaValorTotal() * 4/5) / this.numVencedores;
for (Pessoa vencedor : this.vencedores) {
if (vencedor != null) {
vencedor.setPremiacao(premio);
}
}
return premio;
}
public void pausa(int tempo) {
try {
Thread.sleep(tempo);
} catch (Exception ignored) {}
}
public void imprimeInformacoesTeleSena() {
pausa(1500);
System.out.print("Números sorteados: ");
for (int i = 0; i < 61; i++) {
if (this.teleSenaSorteada[i] == 1) {
System.out.print(i + " ");
pausa(200);
}
}
System.out.println("\n\n+------------------- " +
"Relatório Tele Sena "
+ "-------------------+");
pausa(1000);
System.out.printf("| %-38s\t%d\t\t\t%5s", ("Total de Tele Senas vendidas: "), (300 - this.quantTeleSenasRestantes), "|");
pausa(1000);
System.out.printf("\n| %-38s\t%d\t\t\t%5s", "Quantidade de ganhadores: ", this.numVencedores, "|");
pausa(1000);
System.out.printf("\n| %-38s\t", "Nome(s) do(s) Ganhador(es): ");
pausa(500);
int virg = 0;
for (Pessoa vencedor : this.vencedores) {
if (vencedor != null) {
if (virg > 0) {
System.out.printf("\n|%43s%-16s%1s", " ",(vencedor.getNome()), "|");
}
else {
System.out.printf("%-16s%1s", (vencedor.getNome()), "|");
}
pausa(250);
virg++;
}
}
pausa(1000);
System.out.printf("\n| %-38s\t%s%.2f\t%5s", "Prêmio do(s) sortudo(s):", "R$ ", this.valorPremiacao(), "|");
pausa(1000);
System.out.printf("\n| %-38s\t%s%.2f\t%5s", "Valor total das Tele Senas vendidas:", "R$ ",this.calculaValorTotal(), "|");
pausa(1000);
System.out.printf("\n| %-38s\t%s%.2f\t%5s", "Lucro obtido por Silvio Santos:","R$ ", ((this.calculaValorTotal()) * 1/5), "|");
System.out.println("\n+-----------------------------------------------------------+");
}
}