JAVA学习第7天(15-6-25)

来源:互联网 发布:矩阵lu分解例题 编辑:程序博客网 时间:2024/05/21 17:35
import javax.swing.JOptionPane;


public class ATM {
public static int money = 10000;


public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临,中国建设银行");
boolean b = login();
if (b == false) {
JOptionPane.showMessageDialog(null, "谢谢使用,欢迎下次光临");
System.exit(0);
}


while (true) {
String s = JOptionPane.showInputDialog(null,
"1: 存款\n2: 取款\n3: 查询\n4: 取卡\n请选择:");
int a = Integer.parseInt(s);
switch (a) {
case 1:
saveMoney();
break;
case 2:
getMoney();
break;
case 3:
findMoney();
break;
case 4:
JOptionPane.showMessageDialog(null, "谢谢使用,欢迎下次光临");
System.exit(0);
break;
default:
JOptionPane
.showMessageDialog(null, "非法选择,请选择1-4之间的数字");
break;
}
}
}


/*
* 登陆,返回boolean值。
*/


public static boolean login() {
for (int i = 0; i < 3; i++) {
String code = JOptionPane.showInputDialog(null, "请输入卡号");
String pwd = JOptionPane.showInputDialog(null, "请输入密码");
if (code.equals("12345") && pwd.equals("54321")) {
return true;
} else {
JOptionPane.showMessageDialog(null, "您输入的卡号或密码错误,请重新输入");
}
}
return false;
}


/*
* 查询
*/
public static void findMoney() {
JOptionPane.showMessageDialog(null, "余额为:   " + money);
}


/*
* 存款
*/
public static void saveMoney() {
String a = JOptionPane.showInputDialog(null, "请输入您要存入的金额");
int b = Integer.parseInt(a);
money += b;
String s = JOptionPane.showInputDialog(null, "是否显示余额?y/n");
if (s.equals("y")) {
findMoney();
}
}


/*
* 取款
*/
public static void getMoney() {
String a = JOptionPane.showInputDialog(null, "请输入您要取的金额");
int b = Integer.parseInt(a);
if (b < money) {
money -= b;
String s = JOptionPane.showInputDialog(null, "是否显示余额?y/n");
if (s.equals("y")) {
findMoney();
}
} else {
JOptionPane.showMessageDialog(null, "您的余额不足,非法操作");
}
}
}
0 0
原创粉丝点击