Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. package com.mycompany.centrocomercial;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.Comparator;
  6. import java.util.List;
  7.  
  8. /**
  9. *
  10. * @author UndefinedGadget
  11. */
  12. public class Main {
  13.  
  14. public static void main(String[] args) {
  15.  
  16. //ArrayList que permite guardar as lojas do centro comercial;
  17. List<Loja> listaLojas = new ArrayList();
  18.  
  19. //CentroComercial - Nome e ArrayList
  20. CentroComercial centroComercial = new CentroComercial("NorteShopping", listaLojas);
  21.  
  22. //Lojas Próprias - Área, Nome e Custo de Segurança
  23. centroComercial.addLoja(new Propria(120, "Levis", 700));
  24. centroComercial.addLoja(new Propria(130, "QuickSilver", 675));
  25. centroComercial.addLoja(new Propria(80, "Zara", 500));
  26.  
  27. //Lojas Externas - Área, Nome, Custo de Segurança, Número de Funcionários e Receitas
  28. centroComercial.addLoja(new Externa(135, "Supreme", 720, 12, 350000, 10));
  29. centroComercial.addLoja(new Externa(118, "Gucci", 900, 9, 420000, 7));
  30.  
  31. //Restaurante - Área, Nome, Número de Funcionários, Número de Mesas e Custo de Manutenção
  32. centroComercial.addLoja(new Restaurante(60, "Pizza Hut", 7, 20, 4000));
  33. centroComercial.addLoja(new Restaurante(75, "Burguer King", 11, 35, 6100));
  34. centroComercial.addLoja(new Restaurante(90, "McDonald's", 10, 50, 7000));
  35. centroComercial.addLoja(new Restaurante(55, "H3", 6, 30, 3700));
  36.  
  37. //Quiosque - Área, Nome e Número de Funcionários
  38. centroComercial.addLoja(new Quiosque(25, "Papelaria", 3));
  39. centroComercial.addLoja(new Quiosque(30, "Tabacaria", 4));
  40. centroComercial.addLoja(new Quiosque(40, "Reprografia", 5));
  41.  
  42. //Imprime toString das lojas armazenadas no ArrayList
  43. //for (int i = 0; i < listaLojas.size(); i++) {
  44. // System.out.println(listaLojas.get(i));
  45. //}
  46.  
  47. //Imprime o nome do Centro Comercial
  48. System.out.printf("%n### Nome do Centro Comercial ###%n");
  49. System.out.println(centroComercial.getNomeCC());
  50.  
  51. //Imprime o número de lojas do Centro Comercial
  52. System.out.printf("%n### Número de lojas do Centro Comercial ###%n");
  53. System.out.println(centroComercial.getNumLojas());
  54.  
  55. //Imprime o total de receitas (rendas + segurança) do centro comercial
  56. System.out.printf("%n### Total de receitas (rendas + segurança) do Centro Comercial ###%n");
  57. System.out.printf("%.2f€%n", centroComercial.totalReceitasCC());
  58.  
  59. //Imprime o total das rendas das Lojas Comuns do centro comercial
  60. System.out.printf("%n### Total das rendas das Lojas Comuns do Centro Comercial ###%n");
  61. double percRendaComum = centroComercial.totalRendaLojasComuns() / (centroComercial.totalRendaLojasAncora() + centroComercial.totalRendaLojasComuns()) * 100;
  62. System.out.printf("%.2f€(%.1f%%)%n", centroComercial.totalRendaLojasComuns(), percRendaComum);
  63.  
  64. //Imprime o total do custo de segurança das Lojas Âncoras do centro comercial
  65. System.out.printf("%n### Total do custo de segurança das Lojas Âncoras do Centro Comercial ###%n");
  66. double percCustoSeguranca = centroComercial.totalCustoSegurancaLojasAncoras() / (centroComercial.totalCustoSegurancaLojasAncoras() + centroComercial.totalCustoSegurancaLojasComuns()) * 100;
  67. System.out.printf("%.2f€(%.1f%%)%n", centroComercial.totalCustoSegurancaLojasAncoras(), percCustoSeguranca);
  68.  
  69. //Ordena a renda das lojas (crescente)
  70. Comparator<Loja> ordemCrecentedeRenda = new Comparator<Loja>() {
  71. @Override
  72. public int compare(Loja L1, Loja L2) {
  73. double renda1 = L1.calcularRenda();
  74. double renda2 = L2.calcularRenda();
  75. if (renda1 < renda2) {
  76. return -1;
  77. } else if (renda1 > renda2) {
  78. return 1;
  79. } else {
  80. return 0;
  81. }
  82. }
  83. };
  84.  
  85. //Imprime o nome da loja e respetiva renda em ordem crescente
  86. System.out.printf("%n### Lojas por ordem crescente das rendas ###%n");
  87. List<Loja> contentor2 = centroComercial.getListaLojas();
  88. Collections.sort(contentor2, ordemCrecentedeRenda);
  89. listarForEach(contentor2);
  90.  
  91. //Imprime o nome da loja e respetiva renda em ordem decrescente
  92. System.out.printf("%n### Lojas por ordem decrescente das rendas ###%n");
  93. Collections.sort(contentor2, Collections.reverseOrder(ordemCrecentedeRenda));
  94. listarForEach(contentor2);
  95.  
  96. Comparator<Loja> ordenacaoTipo = new Comparator<Loja>() {
  97. @Override
  98. public int compare(Loja loja1, Loja loja2) {
  99. return Comparator.comparing(Loja::getTipoLoja)
  100. .thenComparing(Loja::getNome)
  101. .compare(loja1, loja2);
  102. }
  103. };
  104. System.out.printf("%n### Lojas por Ordem Alfabetica de Tipos de Loja ###%n");
  105. Collections.sort(contentor2, ordenacaoTipo);
  106. for (int i = 0; i < contentor2.size(); i++) {
  107. System.out.printf("\t%s - %s - %.2f \n", contentor2.get(i).getTipoLoja(),contentor2.get(i).getNome(),contentor2.get(i).calcularRenda());
  108. }
  109. }
  110.  
  111. private static void listarForEach(List<Loja> loja) {
  112. for (Loja l : loja) {
  113. if(l.getNome().length() < 5)
  114. System.out.printf("\t%s - \t\t%.2f\n", l.getNome(), l.calcularRenda());
  115. else
  116. System.out.printf("\t%s - \t%.2f\n", l.getNome(), l.calcularRenda());
  117. }
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement