Advertisement
CrazyDave23

Semestre 2 - Primer Tarea - Candidatos

Aug 10th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.86 KB | None | 0 0
  1. package liceos_semestre_2;
  2.  
  3. /**
  4.  *
  5.  * @author david
  6.  */
  7.  
  8. import java.util.Scanner;
  9.  
  10. public class Liceos_Semestre_2 {
  11.  
  12.  
  13.     public static void main(String[] args) {
  14.        
  15.         //Entrada
  16.             //Generar una matriz con los datos
  17.             Scanner leer = new Scanner(System.in);
  18.            
  19.             String recinto = "";
  20.             char candidato = 'A';
  21.             int suma_total = 0;
  22.             int all_votes = 0;
  23.             double porcentaje = 0;
  24.             int eleccion = 0;
  25.             int eleccion2 = 0;
  26.             int filas = 15;
  27.             int columnas = 4;
  28.            
  29.             int matriz[][] = new int [5][15];
  30.            
  31.             System.out.println("¿Desea mostrar un menú o hacerlo automatizado?"
  32.                     + "\n1. Mostrar Menú \t2.Automatizado");
  33.  
  34.             eleccion = leer.nextInt();
  35.            
  36.             if  (eleccion != 1 && eleccion != 2) {
  37.                 System.err.println("Ingrese uno de los valores dados.");
  38.                 return;
  39.             }
  40.            
  41.             switch(eleccion){
  42.                 case 1:
  43.                     System.out.println("Seleccione una de las opciones:"
  44.                             + "\n1.Generar Tabla    2.Calcular Total"
  45.                             + "    3.Mostrar Tabla    4.Mostrar más votado"
  46.                             + "    5.Generar Gráfico");
  47.                    
  48.                     eleccion2 = leer.nextInt();
  49.                    
  50.                     if (eleccion2 <1 || eleccion2 >5){
  51.                         System.err.println("Ingrese uno de los valores dados.");
  52.                         return;
  53.                     }
  54.                    
  55.                     switch(eleccion2){
  56.                         case 1:
  57.                             generarTabla(matriz, filas, columnas);
  58.                             break;
  59.                         case 2:
  60.                             generarTabla(matriz, filas, columnas);
  61.                             calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
  62.                             break;
  63.                         case 3:
  64.                             generarTabla(matriz, filas, columnas);
  65.                             calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
  66.                             mostrarTabla(matriz, recinto, candidato, filas, columnas, suma_total);
  67.                             break;
  68.                         case 4:
  69.                             generarTabla(matriz, filas, columnas);
  70.                             calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
  71.                             mostrarMasVotado(matriz, suma_total, filas, columnas, candidato);
  72.                             break;
  73.                         case 5:
  74.                             generarTabla(matriz, filas, columnas);
  75.                             calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
  76.                             generarGrafico(matriz, suma_total, filas, columnas);
  77.                             break;
  78.                     }
  79.                     break;
  80.                 case 2:
  81.                     generarTabla(matriz, filas, columnas);
  82.                     calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
  83.                     mostrarTabla(matriz, recinto, candidato, filas, columnas, suma_total);
  84.                     System.out.println("\n");
  85.                     mostrarMasVotado(matriz, suma_total, filas, columnas, candidato);
  86.                     generarGrafico(matriz, suma_total, filas, columnas);
  87.                     break;
  88.             }
  89.     }
  90.    
  91.     public static void generarTabla(int matriz[][], int filas, int columnas){
  92.        
  93.         for (int i = 0; i<columnas ; i++){
  94.             for (int j = 0; j<filas; j++){
  95.  
  96.                 matriz[i][j] = (int) (Math.random() * 5000)+1;
  97.                    
  98.             }
  99.         }
  100.     }
  101.    
  102.     public static void mostrarTabla(int matriz[][], String recinto, char candidato, int filas, int columnas, int suma_total){
  103.  
  104.        
  105.         for (int i = 0; i<columnas ; i++){
  106.            
  107.             for (int j = 0; j<filas; j++){
  108.                
  109.                
  110.                 switch(i){
  111.                     case 0:
  112.                         candidato = 'A';
  113.                         break;
  114.                     case 1:
  115.                         candidato = 'B';
  116.                         break;
  117.                     case 2:
  118.                         candidato = 'C';
  119.                         break;
  120.                     case 3:
  121.                         candidato = 'D';
  122.                         break;
  123.                 }
  124.                
  125.                
  126.                 switch(j){
  127.                     case 0:
  128.                         recinto = "ESCUELA STANDARD D-534 MATTA 0151";
  129.                         break;
  130.                     case 1:
  131.                         recinto = "LICEO B-20 ANIBAL PINTO PINTO 0150";
  132.                         break;
  133.                     case 2:
  134.                         recinto = "ESCUELA D-470 ARTURO PRAT GRAL MACKENNA 685";
  135.                         break;
  136.                     case 3:
  137.                         recinto = "ESCUELA D-499 SAN ANTONIO A VARAS ESQ MATTA";
  138.                         break;
  139.                     case 4:
  140.                         recinto = "LICEO A-23 MARCELA PAZ ANTONIO VARAS 630";
  141.                         break;
  142.                     case 5:
  143.                         recinto = "HOGAR ESTUDIANTIL PRAT ESQ BILBAO";
  144.                         break;
  145.                     case 6:
  146.                         recinto = "INSTITUTO CLARET ZENTENO 453";
  147.                         break;
  148.                     case 7:
  149.                         recinto = "LICEO A-28 P. NERUDA BALMACEDA 650";
  150.                         break;
  151.                     case 8:
  152.                         recinto = "LICEO A-21 BALMACEDA 598";
  153.                         break;
  154.                     case 9:
  155.                         recinto = "ESCUELA MILLARAY RAYEN 01010";
  156.                         break;
  157.                     case 10:
  158.                         recinto = "ESCUELA LLAIMA COQUIMBO 745";
  159.                         break;
  160.                     case 11:
  161.                         recinto = "ESCUELA D-508 GABRIELA MISTRAL SN";
  162.                         break;
  163.                     case 12:
  164.                         recinto = "ESCUELA SAN FRANCISCO MONTT 071";
  165.                         break;
  166.                     case 13:
  167.                         recinto = "ESCUELA D-478 CAUPOLICAN 105";
  168.                         break;
  169.                     case 14:
  170.                         recinto = "ESC STA CAROLINA DE PEDRO DE V P DE VALDIVIA";
  171.                         break;
  172.                 }
  173.                
  174.                 System.out.println("Candidato: "+candidato+" Recinto: "+recinto + " Cant. Votos: "+matriz[i][j]);
  175.                    
  176.             }
  177.         }
  178.        
  179.     }
  180.    
  181.     public static void calcularTotal(int matriz[][], int suma_total, int filas, int columnas, int all_votes, double porcentaje){
  182.          
  183.         for (int i = 0; i<columnas ; i++){
  184.            
  185.             suma_total = 0;
  186.            
  187.             for (int j = 0; j<filas; j++){
  188.  
  189.                 suma_total += matriz[i][j];
  190.  
  191.                
  192.             }
  193.            
  194.             all_votes += suma_total;
  195.  
  196.             porcentaje = ((suma_total*100)/all_votes);
  197.            
  198.  
  199.         }
  200.        
  201.     }
  202.    
  203.     public static void mostrarMasVotado(int matriz[][], int suma_total, int filas, int columnas, char candidato){
  204.        
  205.         int mayor = 0;
  206.         int candidato_mayor = 0;
  207.         char char_candidato = 'D';
  208.        
  209.         for (int i = 0; i<columnas ; i++){
  210.            
  211.             suma_total = 0;
  212.            
  213.             for (int j = 0; j<filas; j++){
  214.                
  215.  
  216.                 suma_total += matriz[i][j];
  217.  
  218.             }
  219.  
  220.             if (suma_total > mayor){
  221.                 mayor = suma_total;
  222.                
  223.                 candidato_mayor = i;
  224.                
  225.  
  226.                
  227.             }
  228.         }  
  229.        
  230.             switch(candidato_mayor){
  231.                     case 0:
  232.                         char_candidato = 'A';
  233.                         break;
  234.                     case 1:
  235.                         char_candidato = 'B';
  236.                         break;
  237.                     case 2:
  238.                         char_candidato = 'C';
  239.                         break;
  240.                     case 3:
  241.                         char_candidato = 'D';
  242.                         break;
  243.                 }
  244.            
  245.         System.out.println("El candidato con más votos es: "+char_candidato+" con: "+mayor+" votos.");
  246.     }
  247.    
  248.     public static void generarGrafico(int matriz[][], int suma_total, int filas, int columnas){
  249.        
  250.         int cuadrito = 0;
  251.         String grafico = "asd";
  252.         char candidato = 'A';
  253.        
  254.         for (int i = 0; i<columnas ; i++){
  255.            
  256.             suma_total = 0;
  257.            
  258.             for (int j = 0; j<filas; j++){
  259.  
  260.                 suma_total += matriz[i][j];
  261.                
  262.             }
  263.            
  264.             cuadrito = (int) (suma_total/5000);
  265.            
  266.             switch (cuadrito){
  267.                 case 1:
  268.                     grafico = "==         |";
  269.                     break;
  270.                 case 2:
  271.                     grafico = "====                 |";
  272.                     break;
  273.                 case 3:
  274.                     grafico = "======               |";
  275.                     break;
  276.                 case 4:
  277.                     grafico = "========             |";
  278.                     break;
  279.                 case 5:
  280.                     grafico = "==========           |";
  281.                     break;
  282.                 case 6:
  283.                     grafico = "============         |";
  284.                     break;
  285.                 case 7:
  286.                     grafico = "==============       |";
  287.                     break;
  288.                 case 8:
  289.                     grafico = "================     |";
  290.                     break;
  291.                 case 9:
  292.                     grafico = "==================   |";
  293.                     break;
  294.                 case 10:
  295.                     grafico = "==================== |";
  296.                     break;
  297.             }
  298.            
  299.             switch (i) {
  300.                 case 0:
  301.                     candidato = 'A';
  302.                     break;
  303.                 case 1:
  304.                     candidato = 'B';
  305.                     break;
  306.                 case 2:
  307.                     candidato = 'C';
  308.                     break;
  309.                 case 3:
  310.                     candidato = 'D';
  311.                     break;
  312.                 default:
  313.                     break;
  314.             }
  315.            
  316.             System.out.println("C"+candidato+" |  "+grafico+suma_total);
  317.            
  318.         }
  319.        
  320.        
  321.     }
  322. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement