-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBanco.java
More file actions
82 lines (78 loc) · 2.98 KB
/
Copy pathBanco.java
File metadata and controls
82 lines (78 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package banco;
import javax.swing.*;
import java.util.Date;
public class Banco{
public double leerValor(String mensaje){
while(true){
try{
String auxiliar = JOptionPane.showInputDialog(mensaje);
if(auxiliar == null || auxiliar.trim().equals("")){
System.exit(0);
}
return Double.parseDouble(auxiliar);
}
catch(NumberFormatException e){
}
}
}
public Banco(){
Date t = new Date();
JOptionPane.showMessageDialog(null, "La fecha es: " + t);
String nom = JOptionPane.showInputDialog("De el nombre");
if(nom == null || nom.trim().equals("")){
System.exit(0);
}
long ced;
while(true){
try{
String auxiliar = JOptionPane.showInputDialog("Numero de cedula de " + nom);
if(auxiliar == null || auxiliar.trim().equals("")){
System.exit(0);
}
ced = Long.parseLong(auxiliar);
break;
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Valor incorrecto");
}
}
CuentaAhorros ref;
if(JOptionPane.showConfirmDialog(null, "Abre cuenta con valor?") == 0){
while(true){
try{
double val = Double.parseDouble(JOptionPane.showInputDialog("Valor inicial de su cuenta"));
ref = new CuentaAhorros(ced, nom, val);
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Valor incorrecto");
}
}
}else{
ref = new CuentaAhorros(ced, nom);
}
JOptionPane.showMessageDialog(null, "Cuenta: " + ref.consultarCuenta());
int i;
do{
String op[] = {"Consignar", "Retirar", "Consultar saldo", "Salir"};
i= JOptionPane.showOptionDialog(null, "Opcion", "Banco", 0, JOptionPane.QUESTION_MESSAGE, null, op, op[0]);
switch(i){
case 0: double val = leerValor("Valor a consignar");
ref.consignar(val);
break;
case 1: val = leerValor("Valor a retirar");
if(ref.retirar(val)){
JOptionPane.showMessageDialog(null, "Retiro: " + val);
}
else{
JOptionPane.showMessageDialog(null, "Saldo insuficiente");
}
break;
case 2: JOptionPane.showMessageDialog(null, "Saldo: " + ref.consultarSaldo());
break;
}
}while(i!=3);
}
public static void main(String[] args) {
new Banco();
}
}