Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package liceos_semestre_2;
- /**
- *
- * @author david
- */
- import java.util.Scanner;
- public class Liceos_Semestre_2 {
- public static void main(String[] args) {
- //Entrada
- //Generar una matriz con los datos
- Scanner leer = new Scanner(System.in);
- String recinto = "";
- char candidato = 'A';
- int suma_total = 0;
- int all_votes = 0;
- double porcentaje = 0;
- int eleccion = 0;
- int eleccion2 = 0;
- int filas = 15;
- int columnas = 4;
- int matriz[][] = new int [5][15];
- System.out.println("¿Desea mostrar un menú o hacerlo automatizado?"
- + "\n1. Mostrar Menú \t2.Automatizado");
- eleccion = leer.nextInt();
- if (eleccion != 1 && eleccion != 2) {
- System.err.println("Ingrese uno de los valores dados.");
- return;
- }
- switch(eleccion){
- case 1:
- System.out.println("Seleccione una de las opciones:"
- + "\n1.Generar Tabla 2.Calcular Total"
- + " 3.Mostrar Tabla 4.Mostrar más votado"
- + " 5.Generar Gráfico");
- eleccion2 = leer.nextInt();
- if (eleccion2 <1 || eleccion2 >5){
- System.err.println("Ingrese uno de los valores dados.");
- return;
- }
- switch(eleccion2){
- case 1:
- generarTabla(matriz, filas, columnas);
- break;
- case 2:
- generarTabla(matriz, filas, columnas);
- calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
- break;
- case 3:
- generarTabla(matriz, filas, columnas);
- calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
- mostrarTabla(matriz, recinto, candidato, filas, columnas, suma_total);
- break;
- case 4:
- generarTabla(matriz, filas, columnas);
- calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
- mostrarMasVotado(matriz, suma_total, filas, columnas, candidato);
- break;
- case 5:
- generarTabla(matriz, filas, columnas);
- calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
- generarGrafico(matriz, suma_total, filas, columnas);
- break;
- }
- break;
- case 2:
- generarTabla(matriz, filas, columnas);
- calcularTotal(matriz, suma_total, filas, columnas, all_votes, porcentaje);
- mostrarTabla(matriz, recinto, candidato, filas, columnas, suma_total);
- System.out.println("\n");
- mostrarMasVotado(matriz, suma_total, filas, columnas, candidato);
- generarGrafico(matriz, suma_total, filas, columnas);
- break;
- }
- }
- public static void generarTabla(int matriz[][], int filas, int columnas){
- for (int i = 0; i<columnas ; i++){
- for (int j = 0; j<filas; j++){
- matriz[i][j] = (int) (Math.random() * 5000)+1;
- }
- }
- }
- public static void mostrarTabla(int matriz[][], String recinto, char candidato, int filas, int columnas, int suma_total){
- for (int i = 0; i<columnas ; i++){
- for (int j = 0; j<filas; j++){
- switch(i){
- case 0:
- candidato = 'A';
- break;
- case 1:
- candidato = 'B';
- break;
- case 2:
- candidato = 'C';
- break;
- case 3:
- candidato = 'D';
- break;
- }
- switch(j){
- case 0:
- recinto = "ESCUELA STANDARD D-534 MATTA 0151";
- break;
- case 1:
- recinto = "LICEO B-20 ANIBAL PINTO PINTO 0150";
- break;
- case 2:
- recinto = "ESCUELA D-470 ARTURO PRAT GRAL MACKENNA 685";
- break;
- case 3:
- recinto = "ESCUELA D-499 SAN ANTONIO A VARAS ESQ MATTA";
- break;
- case 4:
- recinto = "LICEO A-23 MARCELA PAZ ANTONIO VARAS 630";
- break;
- case 5:
- recinto = "HOGAR ESTUDIANTIL PRAT ESQ BILBAO";
- break;
- case 6:
- recinto = "INSTITUTO CLARET ZENTENO 453";
- break;
- case 7:
- recinto = "LICEO A-28 P. NERUDA BALMACEDA 650";
- break;
- case 8:
- recinto = "LICEO A-21 BALMACEDA 598";
- break;
- case 9:
- recinto = "ESCUELA MILLARAY RAYEN 01010";
- break;
- case 10:
- recinto = "ESCUELA LLAIMA COQUIMBO 745";
- break;
- case 11:
- recinto = "ESCUELA D-508 GABRIELA MISTRAL SN";
- break;
- case 12:
- recinto = "ESCUELA SAN FRANCISCO MONTT 071";
- break;
- case 13:
- recinto = "ESCUELA D-478 CAUPOLICAN 105";
- break;
- case 14:
- recinto = "ESC STA CAROLINA DE PEDRO DE V P DE VALDIVIA";
- break;
- }
- System.out.println("Candidato: "+candidato+" Recinto: "+recinto + " Cant. Votos: "+matriz[i][j]);
- }
- }
- }
- public static void calcularTotal(int matriz[][], int suma_total, int filas, int columnas, int all_votes, double porcentaje){
- for (int i = 0; i<columnas ; i++){
- suma_total = 0;
- for (int j = 0; j<filas; j++){
- suma_total += matriz[i][j];
- }
- all_votes += suma_total;
- porcentaje = ((suma_total*100)/all_votes);
- }
- }
- public static void mostrarMasVotado(int matriz[][], int suma_total, int filas, int columnas, char candidato){
- int mayor = 0;
- int candidato_mayor = 0;
- char char_candidato = 'D';
- for (int i = 0; i<columnas ; i++){
- suma_total = 0;
- for (int j = 0; j<filas; j++){
- suma_total += matriz[i][j];
- }
- if (suma_total > mayor){
- mayor = suma_total;
- candidato_mayor = i;
- }
- }
- switch(candidato_mayor){
- case 0:
- char_candidato = 'A';
- break;
- case 1:
- char_candidato = 'B';
- break;
- case 2:
- char_candidato = 'C';
- break;
- case 3:
- char_candidato = 'D';
- break;
- }
- System.out.println("El candidato con más votos es: "+char_candidato+" con: "+mayor+" votos.");
- }
- public static void generarGrafico(int matriz[][], int suma_total, int filas, int columnas){
- int cuadrito = 0;
- String grafico = "asd";
- char candidato = 'A';
- for (int i = 0; i<columnas ; i++){
- suma_total = 0;
- for (int j = 0; j<filas; j++){
- suma_total += matriz[i][j];
- }
- cuadrito = (int) (suma_total/5000);
- switch (cuadrito){
- case 1:
- grafico = "== |";
- break;
- case 2:
- grafico = "==== |";
- break;
- case 3:
- grafico = "====== |";
- break;
- case 4:
- grafico = "======== |";
- break;
- case 5:
- grafico = "========== |";
- break;
- case 6:
- grafico = "============ |";
- break;
- case 7:
- grafico = "============== |";
- break;
- case 8:
- grafico = "================ |";
- break;
- case 9:
- grafico = "================== |";
- break;
- case 10:
- grafico = "==================== |";
- break;
- }
- switch (i) {
- case 0:
- candidato = 'A';
- break;
- case 1:
- candidato = 'B';
- break;
- case 2:
- candidato = 'C';
- break;
- case 3:
- candidato = 'D';
- break;
- default:
- break;
- }
- System.out.println("C"+candidato+" | "+grafico+suma_total);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement