Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package miPack;
- public class Maquina {
- public static void main(String[] args) {
- Cliente juanCarlos = new Cliente ("Juan Carlos", 'M');
- juanCarlos.mostrarCliente();
- CuentaBancaria cuentita = juanCarlos.crearCuenta(10000,true);
- System.out.println(cuentita.extraerDinero(10000));
- System.out.println(cuentita.ingresarDinero(2000));
- System.out.println(cuentita.extraerDinero(3000));
- cuentita.mostrarRegistros();
- }
- }
- /////////////////////////////////// Clase Cliente /////////////////////////////
- package miPack;
- import java.lang.Math;
- public class Cliente {
- private int idCliente;
- private String nombreCliente;
- private char generoCliente;
- public Cliente(String nombreCliente, char genre) {
- this.nombreCliente = nombreCliente;
- this.generoCliente = genre;
- this.idCliente = (int)Math.floor(Math.random()*1000000);
- }
- public String getNombre () {
- return nombreCliente;
- }
- public char getGenero () {
- return generoCliente;
- }
- public int getID () {
- return idCliente;
- }
- public void mostrarCliente () {
- System.out.println("Id" + idCliente + "\nNombre "+ nombreCliente + "\nGenero " + generoCliente);
- }
- public CuentaBancaria crearCuenta (double saldoInicial, boolean deudor) {
- CuentaBancaria nueva = new CuentaBancaria (this, saldoInicial,deudor);
- return nueva;
- }
- }
- ///////////////////////////////////////////////////// Clase Cuenta ///////////////////////////////////////////
- package miPack;
- import java.util.ArrayList;
- public class CuentaBancaria {
- private int idCuenta;
- private double balance;
- private Cliente persona;
- private boolean serDeudor;
- private ArrayList<String> lista = new ArrayList <String>();
- public CuentaBancaria (Cliente person,double saldo,boolean deuda){
- idCuenta = (int)Math.floor(Math.random()*1000000);
- balance = saldo;
- persona = person;
- serDeudor = deuda;
- }
- public double extraerDinero (double retiro) {
- if (serDeudor) {
- if (retiro <= balance+2000)
- {
- balance -= retiro;
- this.agregarRegistro(persona.getNombre(), retiro, 1);
- }
- else {
- System.out.println("Saldo insuficiente" + balance);
- }
- }
- else
- {
- if (retiro <= balance)
- {
- balance -= retiro;
- this.agregarRegistro(persona.getNombre(), retiro, 1);
- }
- else {
- System.out.println("Saldo insuficiente" + balance);
- }
- }
- return balance;
- }
- public double ingresarDinero (double ingreso) {
- balance += ingreso;
- this.agregarRegistro(persona.getNombre(), ingreso, 11241);
- return balance;
- }
- private void agregarRegistro (String nombreDeCliente, double monto,int aux) {
- String mensaje;
- if (aux == 1) {
- mensaje = "El " + nombreDeCliente + ",retiró " + monto + ".";
- }
- else {
- mensaje = "El " + nombreDeCliente + ",depositó " + monto + ".";
- }
- if (lista.size()< 10)
- {
- lista.add(mensaje);
- }
- else
- {
- lista.remove(0);
- lista.add(mensaje);
- }
- }
- public void mostrarRegistros () {
- for (String e : lista) {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment