Skip to content

Commit 1c9a038

Browse files
committed
refactor classes
1 parent 87a6b09 commit 1c9a038

File tree

6 files changed

+185
-26
lines changed

6 files changed

+185
-26
lines changed
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package br.com.fag;
22

3-
/**
4-
* Hello world!
5-
*
6-
*/
7-
public class App
8-
{
9-
public static void main( String[] args )
10-
{
11-
System.out.println( "Hello World!" );
3+
import java.io.FileNotFoundException;
4+
5+
public class App {
6+
public static void main(String[] args) throws FileNotFoundException {
7+
// long inicio = System.currentTimeMillis();
8+
// JsonParser jsonData = new JsonParser("data1.json");
9+
// Calculate calc = new Calculate();
10+
// Float result = calc.calculate(jsonData.parse());
11+
// DataSaver saveJson = new DataSaver();
12+
13+
// saveJson.save(jsonData.parse());
14+
// long fim = System.currentTimeMillis();
15+
16+
// System.out.println("inicio: " + inicio);
17+
// System.out.println("fim: " + fim);
1218
}
1319
}
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package br.com.fag;
22

3-
import br.com.fag.adapter.Enterprise;
4-
import br.com.fag.adapter.Filial;
3+
import br.com.fag.adapter.receive.Enterprise;
54

65
public class Calculate {
76

87
public Float calculate(Enterprise[] listaEmpresas) {
9-
Float result = 0f;
10-
for (Enterprise empresa : listaEmpresas) {
11-
for (Filial filial : empresa.getFiliais()) {
12-
result += filial.getVendaMensal();
13-
}
14-
}
8+
// Float result = 0f;
9+
// for (Enterprise empresa : listaEmpresas) {
10+
// for (Filial filial : empresa.getFiliais()) {
11+
// result += filial.getVendaMensal();
12+
// }
13+
// }
1514

16-
return result;
15+
// return result;
16+
17+
return null;
1718
}
19+
20+
1821

1922
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package br.com.fag;
22

3-
public class WithThreads {
4-
3+
public class WithThreads extends Thread {
4+
public void run() {
5+
6+
}
57
}

threads/src/main/java/br/com/fag/adapter/save/EnterpriseResult.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public class EnterpriseResult {
1010
private Float porcentagemLucro;
1111
private Float porcentagemGastos;
1212
private ArrayList<FilialResult> filias;
13+
private Float imposto;
14+
private Float aluguel;
15+
private Float seguro;
1316

1417
public EnterpriseResult() {
1518
}
@@ -80,4 +83,44 @@ public void setFilias(ArrayList<FilialResult> filias) {
8083
this.filias = filias;
8184
}
8285

86+
public Float getImposto() {
87+
return this.imposto;
88+
}
89+
90+
public void setImposto(Float imposto) {
91+
this.imposto = imposto;
92+
}
93+
94+
public Float getAluguel() {
95+
return this.aluguel;
96+
}
97+
98+
public void setAluguel(Float aluguel) {
99+
this.aluguel = aluguel;
100+
}
101+
102+
public Float getSeguro() {
103+
return this.seguro;
104+
}
105+
106+
public void setSeguro(Float seguro) {
107+
this.seguro = seguro;
108+
}
109+
110+
@Override
111+
public String toString() {
112+
return "{" +
113+
" nome='" + getNome() + "'" +
114+
", totalVendas='" + getTotalVendas() + "'" +
115+
", totalLucro='" + getTotalLucro() + "'" +
116+
", totalGastos='" + getTotalGastos() + "'" +
117+
", porcentagemLucro='" + getPorcentagemLucro() + "'" +
118+
", porcentagemGastos='" + getPorcentagemGastos() + "'" +
119+
", filias='" + getFilias() + "'" +
120+
", imposto='" + getImposto() + "'" +
121+
", aluguel='" + getAluguel() + "'" +
122+
", seguro='" + getSeguro() + "'" +
123+
"}";
124+
}
125+
83126
}

threads/src/main/java/br/com/fag/adapter/save/FilialResult.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,17 @@ public void setPorcentagemGastos(Float porcentagemGastos) {
6868
this.porcentagemGastos = porcentagemGastos;
6969
}
7070

71+
72+
@Override
73+
public String toString() {
74+
return "{" +
75+
" mes='" + getMes() + "'" +
76+
", totalVendas='" + getTotalVendas() + "'" +
77+
", totalLucro='" + getTotalLucro() + "'" +
78+
", totalGastos='" + getTotalGastos() + "'" +
79+
", porcentagemLucro='" + getPorcentagemLucro() + "'" +
80+
", porcentagemGastos='" + getPorcentagemGastos() + "'" +
81+
"}";
82+
}
83+
7184
}
Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,112 @@
11
package br.com.fag;
22

33
import java.io.FileNotFoundException;
4+
import java.util.ArrayList;
45

5-
import br.com.fag.adapter.Enterprise;
6-
import br.com.fag.adapter.Filial;
6+
import br.com.fag.adapter.receive.Enterprise;
7+
import br.com.fag.adapter.receive.Filial;
8+
import br.com.fag.adapter.receive.RegistroMensal;
9+
import br.com.fag.adapter.save.EnterpriseResult;
10+
import br.com.fag.adapter.save.FilialResult;
711

812
public class CalculateTest {
9-
public static void main(String[] args) throws FileNotFoundException {
10-
Float result = 0f;
13+
public static void main() throws FileNotFoundException {
14+
ArrayList<FilialResult> novosRegistros = new ArrayList<>();
15+
ArrayList<EnterpriseResult> novasEmpresas = new ArrayList<>();
16+
Float totalGasto = 0f;
17+
Float totalVenda = 0f;
18+
Float totalLucro = 0f;
1119
Enterprise[] listaEmpresas = new JsonParser("data1.json").parse();
1220
for (Enterprise empresa : listaEmpresas) {
1321
for (Filial filial : empresa.getFiliais()) {
14-
result += filial.getVendaMensal();
22+
for(RegistroMensal registro : filial.getHistoricoDeVendas()) {
23+
FilialResult filialResult = new FilialResult();
24+
filialResult.setTotalVendas(registro.getTotalDeVendas());
25+
filialResult.setTotalGastos(registro.getGasto());
26+
filialResult.setMes(registro.getMes());
27+
filialResult.setPorcentagemGastos((registro.getTotalDeVendas() * registro.getGasto()) / 100);
28+
filialResult.setTotalLucro(registro.getTotalDeVendas() - registro.getGasto());
29+
filialResult.setPorcentagemLucro((registro.getTotalDeVendas() * filialResult.getTotalLucro()) / 100);
30+
novosRegistros.add(filialResult);
31+
totalGasto += registro.getGasto();
32+
totalVenda += registro.getTotalDeVendas();
33+
totalLucro += (registro.getTotalDeVendas() - registro.getGasto());
34+
}
1535
}
36+
EnterpriseResult empresaResult = new EnterpriseResult();
37+
empresaResult.setTotalGastos(totalGasto);
38+
empresaResult.setTotalLucro(totalLucro);
39+
empresaResult.setTotalVendas(totalVenda);
40+
empresaResult.setNome(empresa.getNome());
41+
empresaResult.setFilias(novosRegistros);
42+
43+
novasEmpresas.add(empresaResult);
1644
}
1745

18-
System.out.println(result);
46+
System.out.println(novasEmpresas.toString());
47+
}
48+
49+
// Calcula relatorio de cada mes de uma filial
50+
public static void mainn() throws FileNotFoundException {
51+
ArrayList<FilialResult> novosRegistros = new ArrayList<>();
52+
Enterprise[] listaEmpresas = new JsonParser("data1.json").parse();
53+
for (Enterprise empresa : listaEmpresas) {
54+
for (Filial filial : empresa.getFiliais()) {
55+
for(RegistroMensal registro : filial.getHistoricoDeVendas()) {
56+
FilialResult filialResult = new FilialResult();
57+
filialResult.setTotalVendas(registro.getTotalDeVendas());
58+
filialResult.setTotalGastos(registro.getGasto());
59+
filialResult.setMes(registro.getMes());
60+
filialResult.setPorcentagemGastos((registro.getTotalDeVendas() * registro.getGasto()) / 100);
61+
filialResult.setTotalLucro(registro.getTotalDeVendas() - registro.getGasto());
62+
filialResult.setPorcentagemLucro((registro.getTotalDeVendas() * filialResult.getTotalLucro()) / 100);
63+
novosRegistros.add(filialResult);
64+
}
65+
}
66+
}
67+
68+
System.out.println(novosRegistros);
69+
70+
}
71+
72+
// Capturar a filial que mais vendeu
73+
public static void main(String[] args) throws FileNotFoundException {
74+
ArrayList<FilialResult> novosRegistros = new ArrayList<>();
75+
Float maiorVenda = 0f;
76+
Float maiorGasto = 0f;
77+
String nome = "";
78+
String mesDeMaiorVenda = "";
79+
String mesDeMaiorGasto = "";
80+
Enterprise[] listaEmpresas = new JsonParser("data1.json").parse();
81+
for (Enterprise empresa : listaEmpresas) {
82+
for (Filial filial : empresa.getFiliais()) {
83+
for(RegistroMensal registro : filial.getHistoricoDeVendas()) {
84+
FilialResult filialResult = new FilialResult();
85+
filialResult.setTotalVendas(registro.getTotalDeVendas());
86+
filialResult.setTotalGastos(registro.getGasto());
87+
filialResult.setMes(registro.getMes());
88+
filialResult.setPorcentagemGastos((registro.getTotalDeVendas() * registro.getGasto()) / 100);
89+
filialResult.setTotalLucro(registro.getTotalDeVendas() - registro.getGasto());
90+
filialResult.setPorcentagemLucro((registro.getTotalDeVendas() * filialResult.getTotalLucro()) / 100);
91+
92+
if (registro.getTotalDeVendas() > maiorVenda) {
93+
maiorVenda = registro.getTotalDeVendas();
94+
nome = filial.getNome();
95+
mesDeMaiorVenda = registro.getMes();
96+
}
97+
98+
if (registro.getGasto() > maiorGasto) {
99+
maiorGasto = registro.getGasto();
100+
nome = filial.getNome();
101+
mesDeMaiorGasto = registro.getMes();
102+
}
103+
104+
novosRegistros.add(filialResult);
105+
}
106+
}
107+
}
108+
System.out.println("Nome: " + nome);
109+
System.out.println("Mes de maior venda: " + mesDeMaiorVenda);
110+
System.out.println("Mes de maior gasto: " + mesDeMaiorGasto);
19111
}
20112
}

0 commit comments

Comments
 (0)