Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Problema: un cliente interactua con una caja de ahorro y deposita
- * $100000, ingresando su clave para realizar el depósito
- *
- *
- */
- public class Principal {
- class CajaDeAhorro{
- private float saldo;
- public void depositar(float monto){
- saldo = saldo + monto;
- }
- public void setSaldo(float s){
- saldo = s;
- }
- public float getSaldo(){
- return saldo;
- }
- // Constructor
- CajaDeAhorro(float s){
- saldo = s;
- }
- }
- class Cliente{
- private int DNI;
- private String Clave;
- private CajaDeAhorro Cuenta;
- // Constructor
- Cliente(int d, String c, CajaDeAhorro cda){
- DNI = d;
- Clave = c;
- Cuenta = cda;
- }
- // metodos
- public CajaDeAhorro getCajaDeAhorro(){
- return Cuenta;
- }
- // getters y setters de DNI y Clave
- // ........
- }
- public static void main (String[] args) {
- // Construimos una instancia de caja de ahorro con $50.000
- CajaDeAhorro c1 = new CajaDeAhorro(50000)
- // Construyo el cliente
- Cliente cliente = new Cliente(38555122,"clave",c1)
- // deposito el dinero
- cliente.Cuenta.depositar(100000)
- // verifico el saldo:
- System.out.println("Saldo: " + cliente.Cuenta.getSaldo())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement