Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/04/2011, 14:28
Dracknes
 
Fecha de Ingreso: abril-2011
Mensajes: 23
Antigüedad: 13 años
Puntos: 2
Respuesta: ArrayList dentro de Clases.

Juraría que accedo bien, pero bueno, os pongo lo que tengo.


Código PHP:
package Hoja2_Ampliacion;
import java.util.Scanner;
import java.util.ArrayList;
/**
 *
 * @author Jesús
 */
public class CuentaCorriente {
    public static 
void main(String[] args) {
        
Scanner lectura = new Scanner(System.in);
        
ArrayList<Clienteclientes=new ArrayList<Cliente>();
        
        
clientes.add(new Cliente("Jose"020"Calle Extremadura 1"120));
        
clientes.add(new Cliente("Jesus"021"Calle Extremadura 3"125));
        
        
clientes.get(0).agregarCuenta();
        
        
/*System.out.println("El primer cliente es: "+clientes.get(0).getNombre()+" Con tipo de interés: "+clientes.get(0).obtenerTipoInteres1()+" Con saldo: "+clientes.get(0).getSaldo());*/
    
}

Clase Cuenta:
Código PHP:
package Hoja2_Ampliacion;
class 
Cuenta {

    private 
double tipo_interes;
    private 
double saldo;

    
Cuenta(double tipo_interesdouble saldo){
        
this.tipo_interes=tipo_interes;
        
this.saldo=saldo;
    }

    
void setTipoInteres(double a){
        
tipo_interes=a;
    }
    
void setSaldo(double b){
        
saldo=b;
    }
    
double getTipoInteres(){
        return 
tipo_interes;
    }
    
double getSaldo(){
        return 
saldo;
    }
    
void aumentarSaldo(int saldo){
        if(
saldo<0){
            
saldo=saldo*(-1);
        }
        
this.saldo=this.saldo+saldo;
    }

    
void disminuirSaldo(int saldo){
        if(
saldo>0){
            
saldo=saldo*(-1);
        }
        
this.saldo=this.saldo+saldo;
    }



Clase Cliente
Código PHP:
package Hoja2_Ampliacion;

import java.util.ArrayList;

/**
 *
 * @author Jesús
 */
public class Cliente {
    private 
String nombre;
    private 
int dni;
    private 
String direccion;
    private 
int telefono;
    private 
ArrayList<Cuentacuentas;

    
Cliente(String nombreint dniString direccionint telefono){
        
this.nombre=nombre;
        
this.dni=dni;
        
this.direccion=direccion;
        
this.telefono=telefono;
    }

    
void setNombre(String nombre){
        
this.nombre=nombre;
    }
    
String getNombre(){
        return 
nombre;
    }
    
void setDNI(int dni){
        
this.dni=dni;
    }
    
int getDNI(){
        return 
dni;
    }
    
void setDireccion(String direccion){
        
this.direccion=direccion;
    }
    
String getDireccion(){
        return 
direccion;
    }
    
void setTelefono(int telefono){
        
this.telefono=telefono;
    }
    
int getTelefono(){
        return 
telefono;
    }

    
void agregarCuenta(){
        
cuentas.add(new Cuenta(312,1500));

    }
    
double obtenerTipoInteres1(){
        return 
cuentas.get(0).getTipoInteres();
    }


    
void agregarCuenta2(){
        
cuentas.add(new Cuenta(3512,100500));
    }
    
double obtenerTipoInteres2(){
        return 
cuentas.get(1).getTipoInteres();
    }
    
double getSaldo(){
        return 
cuentas.get(0).getSaldo();
    }
    
double getSaldo1(){
        return 
cuentas.get(1).getSaldo();
    }

A ver si veis el error.

Un saludo y gracias por la ayuda.