Skip to content

Commit 29c3117

Browse files
authored
Add files via upload
1 parent f3a538d commit 29c3117

11 files changed

Lines changed: 96 additions & 59 deletions

File tree

Campeonato/src/main/java/model/Dados.java

Lines changed: 76 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,83 @@
1616
* @author deinfo
1717
*/
1818
public class Dados {
19+
1920
private BufferedReader br = null;
2021
private String nomeArq;
2122
private Jogo jgLinha;
22-
23-
List<Time> lstTimes = new ArrayList<>();
24-
25-
public Dados (String nomeArq) {
26-
this.nomeArq = nomeArq;
27-
}
28-
29-
private Time achaTime (String nomeBusca) {
30-
for (Time t : lstTimes) {
31-
if (t.getNome().equals(nomeBusca)) {
32-
return t;
33-
}
34-
}
35-
Time novoTime = new Time();
36-
return novoTime;
37-
}
38-
39-
private void analisa (Jogo jg) {
40-
Time posTimeA, posTimeB;
41-
42-
posTimeA = achaTime(jg.getTimeA());
43-
posTimeB = achaTime(jg.getTimeB());
44-
45-
}
46-
47-
public List<Time> ler() {
48-
String linha;
49-
try {
50-
br = new BufferedReader (new FileReader(nomeArq));
51-
while ((linha = br.readLine()) != null) {
52-
jgLinha = new Jogo(linha);
53-
}
54-
} catch (Exception e) {
55-
56-
} finally {
57-
try {
58-
if (br != null) {
59-
br.close();
60-
}
61-
} catch (IOException ex) {
62-
63-
}
64-
}
65-
66-
return lstTimes;
67-
}
23+
24+
List<Time> lstTimes = new ArrayList<>();
25+
26+
public Dados(String nomeArq) {
27+
this.nomeArq = nomeArq;
28+
}
29+
30+
private Time achaTime(String nomeBusca) {
31+
for (Time t : lstTimes) {
32+
if (t.getNome().equals(nomeBusca)) {
33+
return t;
34+
}
35+
}
36+
Time novoTime = new Time(nomeBusca);
37+
38+
lstTimes.add(novoTime);
39+
return novoTime;
40+
}
41+
42+
private void analisa(Jogo jg) {
43+
Time posTimeA, posTimeB;
44+
45+
posTimeA = achaTime(jg.getTimeA());
46+
posTimeB = achaTime(jg.getTimeB());
47+
48+
49+
if (jg.getGolA() > jg.getGolB()) { // A ganhou
50+
posTimeA.addVit();
51+
posTimeB.addDer();
52+
} else if (jg.getGolA() < jg.getGolB()) {
53+
posTimeB.addVit();
54+
posTimeA.addDer();
55+
} else {
56+
posTimeA.addEmp();
57+
posTimeB.addEmp();
58+
}
59+
posTimeA.addGolP(jg.getGolA());
60+
posTimeA.addGolN(jg.getGolB());
61+
posTimeB.addGolP(jg.getGolB());
62+
posTimeB.addGolN(jg.getGolA());
63+
}
64+
65+
public List<Time> ler() {
66+
String linha;
67+
try {
68+
br = new BufferedReader(new FileReader(nomeArq));
69+
while ((linha = br.readLine()) != null) {
70+
71+
jgLinha = new Jogo(linha);
72+
73+
analisa(jgLinha);
74+
}
75+
76+
Time aux = new Time();
77+
for (Time t : lstTimes) {
78+
if (t.getPontos() > aux.getPontos())
79+
aux = t;
80+
}
81+
System.out.println("Campeão: " + aux);
82+
83+
} catch (Exception e) {
84+
//System.err.printf("Erro na abertura do arquivo: %s.\n", e.getMessage());
85+
} finally {
86+
try {
87+
if (br != null) {
88+
br.close();
89+
}
90+
} catch (IOException ex) {
91+
92+
}
93+
}
94+
95+
return lstTimes;
96+
}
97+
6898
}

Campeonato/src/main/java/model/Jogo.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @author deinfo
1111
*/
12-
public class Jogo extends Time {
12+
public class Jogo {
1313
String timeA, timeB;
1414
byte golA, golB;
1515

@@ -71,5 +71,10 @@ public Jogo(String timeA, String golA, String timeB, String golB) {
7171
this.golA = Byte.parseByte(golA);
7272
this.golB = Byte.parseByte(golB);
7373
}
74+
75+
@Override
76+
public String toString() {
77+
return "Jogo{" + "timeA=" + timeA + ", timeB=" + timeB + ", golA=" + golA + ", golB=" + golB + '}';
78+
}
7479

7580
}

Campeonato/src/main/java/model/Time.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int saldoGols() {
7171
return golP - golN;
7272
}
7373

74-
int pontos() {
74+
int getPontos() {
7575
return (vit*3) + emp;
7676
}
7777

@@ -105,10 +105,12 @@ public Time() {
105105
public Time(String nome) {
106106
this.nome = nome;
107107
}
108-
109-
108+
110109
@Override
111110
public String toString() {
112-
return "Time{" + "nome=" + nome + '}';
113-
}
111+
return "Time{" + "nome=" + nome + ", vit=" + vit + ", pto=" + getPontos() + ", der=" + der + ", emp=" + emp + ", golP=" + golP + ", golN=" + golN + '}';
112+
}
113+
114+
115+
114116
}

Campeonato/src/main/java/view/PrincipalController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void btnImportarClick(ActionEvent event) {
5252
@Override
5353
public void initialize(URL url, ResourceBundle rb) {
5454
// TODO
55-
dados = new Dados("G:\\jogo.txt");
55+
dados = new Dados("F:\\jogo.txt");
5656

5757
lstPrinc = dados.ler();
5858
}
782 Bytes
Binary file not shown.
866 Bytes
Binary file not shown.
387 Bytes
Binary file not shown.
258 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Generated by Maven
2-
#Tue May 23 23:30:33 BRT 2017
2+
#Wed May 24 23:31:04 BRT 2017
33
version=1.0-SNAPSHOT
44
groupId=com.mycompany
55
artifactId=Campeonato

0 commit comments

Comments
 (0)