|
1 | 1 | package br.com.fag; |
2 | 2 |
|
3 | 3 | import java.io.FileNotFoundException; |
| 4 | +import java.util.ArrayList; |
4 | 5 |
|
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; |
7 | 11 |
|
8 | 12 | 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; |
11 | 19 | Enterprise[] listaEmpresas = new JsonParser("data1.json").parse(); |
12 | 20 | for (Enterprise empresa : listaEmpresas) { |
13 | 21 | 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 | + } |
15 | 35 | } |
| 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); |
16 | 44 | } |
17 | 45 |
|
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); |
19 | 111 | } |
20 | 112 | } |
0 commit comments