Vous êtes sur la page 1sur 2

package frecuencia;

import javax.swing.JOptionPane;
import java.util.ArrayList;
import java.util.List;
public class Moda {
private int[] arreglo;
private int x;
List<Integer> listModa = new ArrayList<Integer>();
public Moda() {
this.x = -1;
this.arreglo = new int[10];
}
public void setNumeros(int num){
if(this.x<10-1){
this.x++;
this.arreglo[x]=num;
}
else
JOptionPane.showMessageDialog(null, "Solo se permiten 10 nmeros");
}
public String getArreglo(){
int i;
String num = "";
for(i=0;i < this.arreglo.length ; i++){
if(i== this.arreglo.length -1)
num += arreglo[i] + "";
else
num += arreglo[i] + ", ";
}
return num;
}
public void hacerOrdenrBurbuja(){
int aux;
for (int k=0;k< arreglo.length;k++){
for (int j=0;j< arreglo.length;j++){
if (arreglo[k]<=arreglo[j]){
aux=arreglo[k];
arreglo[k]=arreglo[j];
arreglo[j]=aux;
}
}
}
}
public String getModas(){
int maxVecRep = 0;
String modas = "";
for(int k =0; k < arreglo.length; k++){
int vecQueRep = 0;
for(int j =0; j < arreglo.length; j++){
if(arreglo[k] == arreglo[j])
vecQueRep++;
}
if(vecQueRep == maxVecRep){
if( listModa.indexOf(arreglo[k]) < 0){
listModa.add(arreglo[k]);
maxVecRep = vecQueRep;
}
}
else{
if(vecQueRep > maxVecRep){
listModa.clear();
listModa.add(arreglo[k]);
maxVecRep = vecQueRep;
}
}
}
if (listModa.size() != arreglo.length){

if(listModa.size() == 1){
modas = "La moda es: " + listModa;
}

if(listModa.size() == 2){
for(int c=0; c < arreglo.length-1; c++){
if(listModa.get(0) == arreglo[c] && listModa.get(1) == arreg
lo[c+1] )
modas = "La moda (promedio) es: " + (listModa.get(0) + lis
tModa.get(1))/2;
}
}

}

if(listModa.size() > 2){
modas = "No existe";
}

return modas;
}
}
..............

Vous aimerez peut-être aussi