Está en la página 1de 9

Cajero: cuarta versin

Ao de la Promocin de la Industria Responsable y del


Compromiso Climtico

UNIVERSIDAD NACIONAL DE
SAN AGUSTIN
FACULTAD DE INGENIERA DE PROCESOS Y SERVICIOS

Escuela profesional de Ingeniera de Sistemas

VENTANA1
APLICACIN MAIN
VENTANA2
CUENTA



CLASE CUENTA

public class Cuenta {

private int cuenta;
private int contrasea;

public Cuenta(int a){
setContrasea(a);
}
public Cuenta(int a,int b){
setCuenta(a);
setContrasea(b);
}

public void setCuenta(int a ){
cuenta =a;
}

public void setContrasea(int b){
contrasea=b;
}

public int getCuenta(){
return cuenta;
}

public int getContrasea(){
return contrasea;
}





}


CLASE VENTANA 1

/import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Ventana1 extends JFrame{

public Cuenta c;
private JTextField text2;
private JTextField text;
public int intentos=4;
private JLabel mensaje;
private JLabel mensaje2;
private Ventana2 a;

public Ventana1(Cuenta z){
c=z;
setTitle("BCP");
setSize(200,250);
setLayout(new FlowLayout());

setDefaultCloseOperation(EXIT_ON_CLOSE);
createContents();
setVisible(true);
}



private void createContents(){
JLabel a=new JLabel("Banco de Credito del Peru ");
JLabel b=new JLabel("Bienvenido....");
JLabel c=new JLabel("Ingrese Numero de Cuenta: ");
JLabel d=new JLabel("Ingrese Contrasea: ");
mensaje=new JLabel();
mensaje2=new JLabel();
JButton boton=new JButton("Entrar");
Listener listener=new Listener();


text =new JTextField(10);
text2=new JTextField(10);


add(a);
add(b);
add(c);
add(text2);
add(d);
add(text);
add(boton);
add(mensaje2);
add(mensaje);

boton.addActionListener(listener);

}

private class Listener implements ActionListener{

public void actionPerformed(ActionEvent e){
String m,m2;
int contrasea,cuenta;
intentos--;
contrasea=Integer.parseInt(text.getText());
cuenta=Integer.parseInt(text2.getText());


if(contrasea==c.getContrasea()&&cuenta==c.getCuenta())
{a=new Ventana2();setVisible(false);
}

else {
m2="Datos Incorrectos!!! ";
m="Le quedan "+ intentos +" intentos";
text.setText("");
text2.setText("");
mensaje2.setText(m2);
mensaje.setText(m);
}
if(intentos==0){
JOptionPane.showMessageDialog(null,"Gracias por
su visita \n"+" adios....");
System.exit(1);
}

}}


}


CLASE VENTANA 2

/import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.Scanner;

import javax.swing.*;


public class Ventana2 extends JFrame {

public Cuenta in=new Cuenta(12345,1234);

private Ventana1 cambio;
private static int cajero=2000;
private static int info=5000;

private JButton boton;
private JButton boton2;
private JButton boton3;
private JButton boton4;
private JButton boton5;
private JButton boton6;

public Ventana2(){
setTitle("Banco de Credito");
setSize(200,300);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
createContents();
setVisible(true);

}
public int getInfo(){
return info;
}

public int getRetiro(int a){
String x;
if(a%50==0&&a<=2000&&cajero-a>=0){
info-=a;
cajero-=a;
return info;}
else if(cajero-a<0){
JOptionPane.showMessageDialog(null,"no contamos con
esa cantidad.... \n vuelva a intentarlo");
x=JOptionPane.showInputDialog("ingrese monto a
Retirar: ");
int b =Integer.parseInt(x);

return getRetiro(b);
}
else{
JOptionPane.showMessageDialog(null,"Numero no
permitido.... \n solo billetes de S/50.0 y menor a S/2000.0 ");
x=JOptionPane.showInputDialog("ingrese monto a
Retirar: ");
int b =Integer.parseInt(x);

return getRetiro(b);
}
}

public int getDeposito(int a){
info+=a;
return info;
}


private void createContents(){
Listener listener=new Listener();
JLabel a=new JLabel(" Elija la operacion ");

setLayout(new GridLayout(7,1));
add(a);


boton=new JButton("Depositar");
boton.addActionListener(listener);
add(boton);

boton2=new JButton("Retiro");
boton2.addActionListener(listener);
add(boton2);

boton3=new JButton("Mi Saldo");
boton3.addActionListener(listener);
add(boton3);

boton4=new JButton("Cambiar Clave");
boton4.addActionListener(listener);
add(boton4);

boton5=new JButton("Ultimos Movimientos");
boton5.addActionListener(listener);
add(boton5);

boton6=new JButton("Salir");
boton6.addActionListener(listener);
add(boton6);



}



private class Listener implements ActionListener{

public void actionPerformed(ActionEvent e){


int b,c,d;
String x,y,z;

if(e.getSource()== boton){
x=JOptionPane.showInputDialog("ingrese monto a
depositar: ");
b =Integer.parseInt(x);

if(b%50==0){
JOptionPane.showMessageDialog(null,"Su saldo
es ahora: "+getDeposito(b));

}
else

JOptionPane.showMessageDialog(null,"Numero no permitido.... \n solo
billetes de S/50.0 ");
}
else
if(e.getSource()== boton2){
y=JOptionPane.showInputDialog("ingrese
monto a retirar: ");
c =Integer.parseInt(y);

JOptionPane.showMessageDialog(null,"Su
saldo es ahora: "+getRetiro(c));

}
else
if(e.getSource()== boton3){

JOptionPane.showMessageDialog(null,"Su saldo es : "+getInfo());

}
else
if(e.getSource()== boton4){
for (int i = 0; i < 10; i++)
{

z=JOptionPane.showInputDialog("ingrese nueva Contrasea: ");
d =Integer.parseInt(z);
if(d>=1000&&d<10000){
in.setContrasea(d);

JOptionPane.showMessageDialog(null,"Su nueva Contrasea es:
"+in.getContrasea());break;
}
else

JOptionPane.showMessageDialog(null,"La Contrasea debe tener 4
digitos: \n Vuelva a intentarlo ");
}
}
else
if(e.getSource()== boton5){
try {
PrintWriter
tip=new PrintWriter(new FileWriter("Movimientos.txt",true));
Scanner file=new
Scanner(new FileReader("Movimientos.txt"));


tip.println("Deposito: ");

tip.println("retiro: ");

tip.println("cosulta de saldo: "+getInfo());
tip.close();

while(file.hasNextLine())System.out.println(file.nextLine());

file.close();

} catch (IOException
e1) {

e1.printStackTrace();
}

}
else
if(e.getSource()== boton6){

cambio=new Ventana1(in);

setVisible(false);
}

} } }




CLASE DEMOCAJERO

/public class DemoCajero {
public static void main(String[] args) {
Cuenta c=new Cuenta(12345,1234);
Ventana1 b=new Ventana1(c);
}
}











RECULTADO GUI

También podría gustarte