elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  colecciones
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: colecciones  (Leído 1,341 veces)
pipelojunior

Desconectado Desconectado

Mensajes: 4


Ver Perfil
colecciones
« 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
   


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
una duda con colecciones
Java
RockAqp 1 1,968 Último mensaje 26 Mayo 2010, 22:36 pm
por Leyer
[VB.NET(FrameWork)] Matriz (arrays) o Colecciones?
.NET (C#, VB.NET, ASP)
gnxa95 2 2,214 Último mensaje 15 Julio 2018, 17:40 pm
por Eleкtro
MOVIDO: [VB.NET(FrameWork)] Matriz (arrays) o Colecciones?
Programación Visual Basic
Eleкtro 0 1,193 Último mensaje 15 Julio 2018, 17:40 pm
por Eleкtro
[Aporte] Screencast: cómo filtrar colecciones usando Doctrine ORM
PHP
mchojrin 0 1,427 Último mensaje 15 Noviembre 2018, 17:22 pm
por mchojrin
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines