Advertisement
MatiasDicro

Guia Nº3 parte 2.

Apr 7th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. package miPack;
  2.  
  3. public class Maquina {
  4.  
  5.     public static void main(String[] args) {
  6.         Cliente juanCarlos = new Cliente ("Juan Carlos", 'M');
  7.         juanCarlos.mostrarCliente();
  8.         CuentaBancaria cuentita = juanCarlos.crearCuenta(10000,true);
  9.         System.out.println(cuentita.extraerDinero(10000));
  10.         System.out.println(cuentita.ingresarDinero(2000));
  11.         System.out.println(cuentita.extraerDinero(3000));
  12.         cuentita.mostrarRegistros();
  13.     }
  14.  
  15. }
  16.  
  17. /////////////////////////////////// Clase Cliente /////////////////////////////
  18.  
  19. package miPack;
  20. import java.lang.Math;
  21.  
  22. public class Cliente {
  23.     private int idCliente;
  24.     private String nombreCliente;
  25.     private char generoCliente;
  26.    
  27.     public Cliente(String nombreCliente, char genre) {
  28.         this.nombreCliente = nombreCliente;
  29.         this.generoCliente = genre;
  30.         this.idCliente = (int)Math.floor(Math.random()*1000000);
  31.     }
  32.     public String getNombre () {
  33.         return nombreCliente;
  34.     }
  35.     public char getGenero () {
  36.         return generoCliente;
  37.     }
  38.     public int getID () {
  39.         return idCliente;
  40.     }
  41.     public void mostrarCliente () {
  42.         System.out.println("Id" + idCliente + "\nNombre "+ nombreCliente + "\nGenero " + generoCliente);
  43.     }
  44.     public CuentaBancaria crearCuenta (double saldoInicial, boolean deudor) {
  45.         CuentaBancaria nueva = new CuentaBancaria (this, saldoInicial,deudor);
  46.         return nueva;
  47.     }
  48.    
  49. }
  50. ///////////////////////////////////////////////////// Clase Cuenta ///////////////////////////////////////////
  51. package miPack;
  52. import java.util.ArrayList;
  53.  
  54. public class CuentaBancaria {
  55.     private int idCuenta;
  56.     private double balance;
  57.     private Cliente persona;
  58.     private boolean serDeudor;
  59.     private ArrayList<String> lista = new ArrayList <String>();
  60.    
  61.     public CuentaBancaria (Cliente person,double saldo,boolean deuda){
  62.         idCuenta = (int)Math.floor(Math.random()*1000000);
  63.         balance = saldo;
  64.         persona = person;
  65.         serDeudor = deuda;
  66.     }
  67.    
  68.     public double extraerDinero (double retiro) {
  69.         if (serDeudor) {
  70.             if (retiro <= balance+2000)
  71.             {
  72.                 balance -= retiro;
  73.                 this.agregarRegistro(persona.getNombre(), retiro, 1);
  74.             }
  75.             else {
  76.                 System.out.println("Saldo insuficiente" + balance);
  77.             }
  78.         }
  79.         else
  80.         {
  81.             if (retiro <= balance)
  82.             {
  83.                 balance -= retiro;
  84.                 this.agregarRegistro(persona.getNombre(), retiro, 1);
  85.             }
  86.             else {
  87.                 System.out.println("Saldo insuficiente" + balance);
  88.             }
  89.         }
  90.         return balance;
  91.     }
  92.     public double ingresarDinero (double ingreso) {
  93.         balance += ingreso;
  94.         this.agregarRegistro(persona.getNombre(), ingreso, 11241);
  95.         return balance;
  96.     }
  97.     private void agregarRegistro (String nombreDeCliente, double monto,int aux) {
  98.         String mensaje;
  99.         if (aux == 1) {
  100.             mensaje = "El " + nombreDeCliente + ",retiró " + monto + ".";
  101.         }
  102.         else {
  103.             mensaje = "El " + nombreDeCliente + ",depositó " + monto + ".";
  104.         }
  105.         if (lista.size()< 10)
  106.         {
  107.             lista.add(mensaje);
  108.         }
  109.         else
  110.         {
  111.             lista.remove(0);
  112.             lista.add(mensaje);
  113.         }
  114.     }
  115.     public void mostrarRegistros () {
  116.         for (String e : lista) {
  117.             System.out.println(e);
  118.         }
  119.     }
  120.    
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement