Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 60 additions & 216 deletions Array_Elecciones.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,239 +10,83 @@
*/
/* codigo ingresado*/

correcion agregada

correcion agregada
import javax.swing.*;
import java.util.Scanner;

public class ArrayElecciones {


public static void main(String args[]) {
//ivan mauricio leal alvarez----------------
Scanner teclado = new Scanner(System.in);//---creando objeto para pedir datos por teclado
// variables inicializadas
// Arreglos
// matriz inicializado con 5 candidatos
String Candidatos [] = { " Juan" , " Pedro" ,"jesus","manuel","pepito" };
public static void main(String args[]) {


//ivan mauricio leal alvarez----------------

// Arreglos
// matriz inicializado con 5 candidatos
String Candidatos [] = { " Juan" , " Pedro" ,"Jesus","Manuel","Ismael" };

// matriz inicializado con 6 sedes
String SedeFila [] = { " Aguazul ", "trinidad","paz deariporo","pore","tauramena" };
// matriz inicializado con 29 sedes
String SedeFila [] = { " APARTADO ", " ARMENIA "," BOGOTÀ "," BUCARAMANGA "," BUGA "," CALI "," CARTAGO "," CAUCASIA "," CUCUTA ",
" DUITAMA "," IBAGUE "," IPIALES "," MANIZALES "," MEDELLIN ", " MONTERIA "," PALMIRA "," PASTO "," PEREIRA ",
" POPAYAN "," QUIBDO "," RIONEGRO "," SAHAGUN "," SINCELEJO "," SOGAMOSO "," TULUA "," TUMACO "," TUNJA "," VILLAVICENCO "," YOPAL "};

// matriz que almacena los votos
int f,c;
int[][] Votos;
int []vecres;
int numerom=0;
String casilla = null;
Votos = new int [5][6];
vecres= new int [5];
//------------John Fredy Bonilla-----------------------
// matriz que almacena los votos
int Votos [][];
int veces [];

// variables inicializadas
int SedeFil=29;
int CandiColum=5;

//------------John Fredy Bonilla-----------------------

// ingreso de votos
for(f=0 ; f< SedeFila.length ; f++)
{
for(c=0 ; c< Candidatos.length;c++)
{
System.out.println("Porfavor ingrese la cantidad de votos que saco en el municipio ("+SedeFila[f]+") el candidato ("+Candidatos[c]+") ");
// Votos[SedeFila][CandiColum]=teclado.nextInt();//
Votos[f][c]= teclado.nextInt();
// ingreso de votos
Votos = new int[SedeFil][CandiColum];
for(int f=0 ; f< SedeFila.length ; f++){
for(int c=0 ; c< Candidatos.length;c++){
Votos[f][c] = Integer.parseInt(JOptionPane.showInputDialog("Porfavor ingrese la cantidad de votos que saco en la sede "
+SedeFila[f]+ " el candidato " +Candidatos[c]));
}
}
//operacion suma por columnas
for(f=0 ; f< SedeFila.length ; f++)
{
int sumaC=0;
for(c=0 ; c< Candidatos.length;c++)
{
sumaC=Votos[c][f]+sumaC;
vecres[f]=sumaC;

}
System.out.println("candidato "+Candidatos[f]+" resultado es: " + vecres[f]);

}

//contibucion carlos cogua
// comparacion de puntuacion mayor
for(f=0 ; f< SedeFila.length ; f++)
{
if(vecres[f]>vecres[f])
{
numerom = vecres[0];
casilla = Candidatos[f];

}
else
{
if(vecres[f]>numerom)
{
numerom =vecres[f];
casilla = Candidatos[f];
}

}
}
System.out.println("Con una votacion de "+ numerom+ " el candidadto ganador para director de sede yopal es ; " +casilla);

}


✰✰✰✰✰--ZARYS VARGAS--✰✰✰✰✰✰

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
*
* @author PORTATIL
*/
public class Votaciones {


public static void main(String[] args) {



String candidatos[], sedes[];
int votos[][];


int fil, col;

JTextArea area = new JTextArea(15, 30);
JScrollPane scroll = new JScrollPane(area);

fil = Integer.parseInt(JOptionPane.showInputDialog("ingrese el numero de las sedes"));
sedes = new String[fil];

for (int x = 0; x < fil; x++) {
sedes[x] = JOptionPane.showInputDialog("nombre para la sede N:" + (x + 1));
}


col = Integer.parseInt(JOptionPane.showInputDialog("Ingrese e numero de candidatos"));
candidatos = new String[col];
for (int x = 0; x < col; x++) {
candidatos[x] = JOptionPane.showInputDialog("nombre del candidato n:" + (x + 1));
}

votos = new int[fil][col];

for (int x = 0; x < fil; x++) {
for (int y = 0; y < col; y++) {
votos[x][y] = Integer.parseInt(JOptionPane.showInputDialog("ingrese los votos de la sede " + sedes[x] + " paea el candidato " + candidatos[y]));


//operacion suma por columnas
veces = new int[Candidatos.length];
for (int y=0; y<CandiColum; y++){
for (int x=0;x<SedeFil;x++){
veces[y] +=Votos[x][y];
}
}


int[] totalVotos = new int[candidatos.length];
for (int y = 0; y < col; y++) {
for (int x = 0; x < fil; x++) {
totalVotos[y] += votos[x][y];
}
}


int max = 0;
int pos = 0;
for (int i = 0; i < totalVotos.length; i++) {
if (max < totalVotos[i]) {
max = totalVotos[i];
pos = i;
}
}


area.append("candidato con mayoria de votos:" + candidatos[pos] + "Total de votos" + totalVotos[pos]);
//contibucion karen
// comparacion de puntuacion mayor
int comparacion =0;
int cas=0;

for (int i = 0; i < fil; i++) {
area.append("\n" + sedes[i]);
for (int x = 0; x < col; x++) {
area.append("\n" + candidatos[x]);
area.append("\t" + votos[i][x]);
for (int i=0; i<veces.length; i++){
if (comparacion < veces [i]){
comparacion = veces [i];
cas=i;
}
}
}


JOptionPane.showMessageDialog(null, scroll);

}//fin del main

}//fin de la clase principal

// Aporte darwin castañeda, posible solucion del ejercicio.

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class votaciones {

public static void main (String a[]){
String candidatos[], sedes[];
int votos[][], fila, colum;

JTextArea area= new JTextArea(15, 30);;
JScrollPane scroll = new JScrollPane(area);
fila = Integer.parseInt(JOptionPane.showInputDialog
("Por favor ingrese el número de sedes:"));


sedes = new String[fila];
for (int x = 0; x < fila; x++){
sedes[x] = JOptionPane.showInputDialog("Por favor ingres el nombre de la Sede No :"+(x+1));

}

colum = Integer.parseInt(JOptionPane.showInputDialog ("Por favor ingrese el número de candidatos:"));
candidatos = new String[colum];
for (int x = 0; x < colum; x++){
candidatos[x] = JOptionPane.showInputDialog("por favor ingrese el nombre del Candidato No :"+(x+1) );

}

votos = new int[fila][colum];
for (int x = 0; x < fila; x++){
for (int y = 0; y < colum; y++){
votos[x][y] = Integer.parseInt(JOptionPane.
showInputDialog("**Ingrese los votos de la sede** " + sedes [x] + " para el candidato " + candidatos [y] ));
}

}


int[] totalv = new int[candidatos.length];
for (int y = 0; y < colum; y++){
for (int i = 0; i < fila; i++){
totalv[y] += votos[i][y];
}

}


int max = 0;
int pos = 0;
for (int i = 0; i < totalv.length; i++){
if ( max < totalv[i] ){
max = totalv[i];
pos = i;
}
}
JTextArea area = new JTextArea(15, 30);
JScrollPane scroll = new JScrollPane(area);

area.append("Candidato que obtubo la mayoría de votos es: " + candidatos [pos] +" °°Total de Votos obtenidos:°° " + totalv [pos]);
// ----- darwin castañeda--------------

area.append("El candidato que obtuvo la mayoría de votos es: " + veces[cas] +" -- Total de Votos obtenidos: " + Candidatos[cas]);

for (int i = 0; i < fila; i++){
area.append("\n"+sedes[i]);
for (int x = 0; x < colum; x++){
area.append("\n"+candidatos[x]);
area.append("\t"+votos[i][x]);

}
}
JOptionPane.showMessageDialog(null, scroll);

}
}
for (int i = 0; i < SedeFila.length; i++){
area.append("\n"+SedeFila[i]);
for (int x = 0; x < Candidatos.length; x++){
area.append("\n"+Candidatos[x]);
area.append("\t"+Votos[i][x]); //HAY QUE MODIFICAR LA ESTRUCTURA DE COMO IMPRIME EN PANTALLA
}
}
JOptionPane.showMessageDialog(null, scroll);
}
}