JAVA POO
Ejercicio 5
─Aclaración: Se hace uso de proceso, entidad y control. Lo
plantee como si fuera un menú de banco real.
Programa Principal
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ejercicio5;
import [Link].Cuenta_Bancaria;
import [Link].Cuenta_Bancaria_Servicio;
import [Link];
/**
*
* @author Cristian
*/
public class ejercicio5 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Cuenta_Bancaria_Servicio CBD = new Cuenta_Bancaria_Servicio();
Cuenta_Bancaria CBO = [Link]();
Menu();
Operaciones(CBO);
public static void Menu() {
[Link]("MENU");
[Link]("1-Ingresar dinero");
[Link]("2-Retirar dinero");
2
[Link]("[Link] Rapida");
[Link]("4-Consultar Saldo");
[Link]("5-Consultar Mis Datos");
[Link]("6-Salir");
}
public static void Operaciones(Cuenta_Bancaria CBO) {
Scanner leer = new Scanner([Link]).useDelimiter("\n");
int opc;
String verificacion = "";
do {
[Link]("opc ➤");
opc = [Link]();
switch (opc) {
case 1:
[Link]("Ingrese monto: $");
[Link]([Link]());
break;
case 2:
[Link]("Ingrese monto: $");
[Link]([Link]());
break;
case 3:
[Link]("Ingrese monto: $");
CBO.extraccion_rapida([Link]());
break;
case 4:
[Link]("Su saldo es: $" + [Link]() + "\n");
break;
case 5:
[Link]("Datos de la cuenta:");
[Link]([Link]());
break;
case 6:
[Link]("¿Desea terminar la operacion (S/N)?");
verificacion = [Link]();
default:
if () {
[Link]("La opccion elegida es incorrecta.");
}
}
} while (opc < 6 || );
}
}
3
//////////////////////////////////////////////////////////////////////
Atributos( Crear un new package y declarar en un [Link] llamada
cuenta bancaria)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package [Link];
/**
*
* @author Cristian
*/
public class Cuenta_Bancaria {
private int numeroCuenta;
private long DNICliente;
private double saldo;
public Cuenta_Bancaria() {
[Link] = 5000;
}
public Cuenta_Bancaria(int numeroCuenta, long DNICliente) {
[Link] = numeroCuenta;
[Link] = DNICliente;
[Link] = 5000;
}
public void setSaldo(double saldo) {
[Link] = saldo;
}
public void setNumeroCuenta(int numeroCuenta) {
[Link] = numeroCuenta;
}
public void setDNICliente(long DNICliente) {
4
[Link] = DNICliente;
}
public int getNumeroCuenta() {
return numeroCuenta;
}
public long getDNICliente() {
return DNICliente;
}
public double getSaldo() {
return saldo;
}
public double ingresar(double monto_i) {
saldo += monto_i;
return saldo;
}
public double retirar(double monto_r) {
if ([Link] < monto_r) {
[Link]("➪ Saldo Insufientes");
return 0;
} else {
saldo -= monto_r;
return saldo;
}
}
public double extraccion_rapida(double monto_e) {
if (monto_e <= (0.2 * [Link])) {
[Link] -= monto_e;
return [Link];
}
[Link]("➪ No puede extraer mas del 20% del saldo");
return 0;
}
@Override
public String toString() {
return "Cuenta_Bancaria{" + "numeroCuenta=" + numeroCuenta + ", DNICliente=" +
DNICliente + ", saldo=" + saldo + '}';
}
}
5
//////////////////////////////////////////////////////////////////////
Entidad y Control( Crear un new package y declarar en un [Link]
llamada cuenta bancaria servicio)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package [Link];
import [Link].Cuenta_Bancaria;
import [Link];
/**
*
* @author Cristian
*/
public class Cuenta_Bancaria_Servicio {
private Scanner leer = new Scanner([Link]).useDelimiter("\n");
public Cuenta_Bancaria datoscliente (){
[Link]("BIENVENIDO AL BANCO EGG");
[Link]("Para iniciar sesion ingrese los siguentes datos");
[Link]("Ingrese numero de cuenta: ");
int numeroCuenta=[Link]();
[Link]("Ingrese el DNI: ");
long DNICliente=[Link]();
return new Cuenta_Bancaria(numeroCuenta, DNICliente);
}
}