Foro de elhacker.net

Programación => Programación General => Mensaje iniciado por: pipelojunior en 26 Abril 2012, 16:48 pm



Título: colecciones
Publicado por: pipelojunior en 26 Abril 2012, 16:48 pm
Hola buenas resulata que tengo este problema a ver si alguien me puedes ayudar por un lado tengo esta clase:
/**
 * Store details of a club membership.
 *
 * @author David J. Barnes and Michael Kolling
 * @version 2006.03.30
 */
public class Socio
{
    // The name of the member.
    private String nombre;
    // The month in which the membership was taken out.
    private int mes;
    // The year in which the membership was taken out.
    private int año;
   
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public Socio()
    {
        // put your code here
       
    }


    /**
     * Constructor for objects of class Membership.
     * @param name The name of the member.
     * @param month The month in which they joined. (1 ... 12)
     * @param year The year in which they joined.
     */
    public Socio(String nombre, int mes, int año)
        throws IllegalArgumentException
    {
        if(mes < 1 || mes > 12) {
            throw new IllegalArgumentException(
                "Mes " + mes + " el parametro esta fuera del rango 1 ... 12");
        }
        this.nombre = nombre;
        this.mes= mes;
        this.año = año;
    }
   
    /**
     * @return The member's name.
     */
    public String getNombre()
    {
        return nombre;
    }
   
    /**
     * @return The month in which the member joined.
     *         A value in the range 1 ... 12
     */
    public int getMes()
    {
        return mes;
    }

    /**
     * @return The year in which the member joined.
     */
    public int getAño()
    {
        return año;
    }

    /**
     * @return A string representation of this membership.
     */
    public String toString()
    {
        return "Nombre: " +nombre +
               " joined in month " +
               mes + " of " + año;
    }
}
luego ten go la clase club que utiliza la clase socio entonces me piden que agrege un metodo ala clase club que me diga los socias que se afiliaron tal mes .el mes es introducido en el metodo he hecho algo asi pero no me sale
clase club

import java.util.ArrayList;

/**
 * Store details of club memberships.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Club
{
    private ArrayList<Socio> socios;
   
    /**
     * Constructor for objects of class Club
     */
    public Club()
    {
        socios=new ArrayList<Socio>();
       
    }

    /**
     * metodo para inscribir un nuevo socio al club.
     * lo podemos asociar mediante parametros.
     */
    public void agregarSocios(String nombre, int mes, int año)
    {
        socios.add(new Socio( nombre,mes,  año));

    }
   
     /**
     * metodo para inscribir un nuevo socio al club otra manera
     * lo podemos asociar mediante parametros.
     */
    public void agregarSociosVariante(Socio nuevoSocio)
    {
        socios.add(nuevoSocio );

    }
   
    /**
     *
     */
    public int asociadoEnMes(int mes)
     throws IllegalArgumentException
    {
         if(mes < 1 || mes > 12) {
            throw new IllegalArgumentException(
                "Mes " + mes + " el parametro esta fuera del rango 1 ... 12");
        }
       
        int asociadoEnMes=0;
        int indice=0;
        while(indice<socios.size()){
            if((socios.get(indice)). getMes()==mes){
                asociadoEnMes= asociadoEnMes+socios.get(indice);}
                return asociadoEnMes;}
       
    }

   
   
   
   
   
   

    /**
     * @return The number of members (Membership objects) in
     *         the club.
     */
    public int numberDeSocios()
    {
        return socios.size();
    }
   
aver si me podeis ayudar gracias