Advertisement
LightProgrammer000

Votacao eleitoral

Feb 21st, 2020
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.83 KB | None | 0 0
  1. package Tarefas_1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class EX_08
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         // Apresentacao
  10.         System.out.println("# Programa EX_08");
  11.        
  12.         try
  13.         {
  14.             // Variaveis
  15.             int qtd_1 = 0;
  16.             int qtd_2 = 0;
  17.             int qtd_3 = 0;
  18.             int qtd_4 = 0;
  19.             int qtd_5 = 0;
  20.             int qtd_6 = 0;
  21.  
  22.             // Controle
  23.             int qtd_tot_vot = 0;
  24.  
  25.             // Estrutura de repeticao
  26.             while(true)
  27.             {
  28.                 switch(menu())
  29.                 {
  30.                     // Relatorio
  31.                     case 0:
  32.                         relatorio(qtd_1, qtd_2, qtd_3, qtd_4, qtd_5, qtd_6, qtd_tot_vot);
  33.                         System.exit(0);
  34.                         break;
  35.  
  36.                     // Candidato 1
  37.                     case 1:
  38.                         qtd_1 ++;
  39.                         break;
  40.  
  41.                     // Candidato 2
  42.                     case 2:
  43.                         qtd_2 ++;
  44.                         break;
  45.  
  46.                     // Candidato 3
  47.                     case 3:
  48.                         qtd_3 ++;
  49.                         break;
  50.  
  51.                     // Candidato 4
  52.                     case 4:
  53.                         qtd_4 ++;
  54.                         break;    
  55.  
  56.                     // Voto nulo
  57.                     case 5:
  58.                         qtd_5 ++;
  59.                         break;
  60.  
  61.                     // Voto em branco
  62.                     case 6:
  63.                         qtd_6 ++;
  64.                         break;
  65.  
  66.                     default:
  67.                         break;
  68.                 }
  69.  
  70.                 // Contagem de votos
  71.                 qtd_tot_vot ++;
  72.             }
  73.         }
  74.  
  75.         catch (Exception e)
  76.         {
  77.             //System.err.println(e);            
  78.         }
  79.     }
  80.  
  81.     // Funcao: Menu
  82.     private static int menu()
  83.     {
  84.         // Variavel
  85.         int opc;
  86.  
  87.         // Instanciacao
  88.         Scanner ent = new Scanner(System.in);
  89.  
  90.         // Apresentacao
  91.         System.out.println("\n---------- Menu ----------");
  92.         System.out.println("* [1] Candidato - 1 ");
  93.         System.out.println("* [2] Candidato - 2 ");
  94.         System.out.println("* [3] Candidato - 3 ");
  95.         System.out.println("* [4] Candidato - 4 ");
  96.         System.out.println("* [5] Voto nulo");
  97.         System.out.println("* [6] Voto em branco");
  98.         System.out.println("* [0] Finalizar conjunto de votos");
  99.         System.out.println("---------------------------------");
  100.         System.out.print("* Opc: ");
  101.         opc = ent.nextInt();
  102.  
  103.         while ( !(opc >= 0 && opc <= 6) )
  104.         {
  105.             // Apresentacao
  106.             System.out.println("\n Nenhum voto computado !!!");
  107.             System.out.println("\n---------- Menu ----------");
  108.             System.out.println("* [1] Candidato - 1 ");
  109.             System.out.println("* [2] Candidato - 2 ");
  110.             System.out.println("* [3] Candidato - 3 ");
  111.             System.out.println("* [4] Candidato - 4 ");
  112.             System.out.println("* [5] Voto nulo");
  113.             System.out.println("* [6] Voto em branco");
  114.             System.out.println("* [0] Finalizar conjunto de votos");
  115.             System.out.println("---------------------------------");
  116.             System.out.print("* Opc: ");
  117.             opc = ent.nextInt();      
  118.         }
  119.  
  120.         return opc;
  121.     }
  122.  
  123.     // Metodo: Relatorio
  124.     private static void relatorio(int qtd_1, int qtd_2, int qtd_3, int qtd_4, int qtd_5, int qtd_6, int qtd_tot_vot)
  125.     {
  126.         // Estrutura de decisao
  127.         if (qtd_tot_vot > 0)
  128.         {
  129.             System.out.println("\n---------- RELATORIO ----------");
  130.             System.out.println("# Votos (candidatos 1): " + qtd_1);
  131.             System.out.println("# Votos (candidatos 2): " + qtd_2);
  132.             System.out.println("# Votos (candidatos 3): " + qtd_3);
  133.             System.out.println("# Votos (candidatos 4): " + qtd_4);
  134.             System.out.println("# Votos nulos: " + qtd_5);
  135.             System.out.println("# Votos em branco: " + qtd_6);  
  136.             System.out.println("# Total de votos: " + qtd_tot_vot);
  137.             System.out.println("# Total de votos validos: " + (qtd_tot_vot - (qtd_5 + qtd_6)));
  138.             System.out.println("# Percentual de votos nulos: " + qtd_5 * 100 / qtd_tot_vot + "%");
  139.             System.out.println("# Percentual de votos brancos: " + qtd_6 * 100 / qtd_tot_vot + "%");
  140.             System.out.println("----------------------------------");
  141.         }
  142.  
  143.         else
  144.         {
  145.             System.out.println("\n---------- RELATORIO ----------");
  146.             System.out.println("# Total de votos: " + qtd_tot_vot);
  147.             System.out.println("----------------------------------");
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement