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, "您的余额不足,非法操作");
}
}
}
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
- JAVA学习第7天(15-6-25)
- java学习第15天
- JAVA 学习第7天
- Java学习第25天:正则表达式
- JAVA学习第6天(1)接口1
- 学习java第6天 模仿XP画板(10%)
- java反射机制(SSH学习第7天)
- JAVA 学习第3天(1)
- JAVA 学习第3天(2)
- java学习第5天
- java 学习第10天
- JAVA学习第8天
- JAVA学习 第5天
- JAVA学习第8天
- JAVA学习第10天
- JAVA 学习第1天
- 学习java第10天
- 学习java第11天
- DOM解析XML
- Ubuntu安装virtualbox
- leetcode 二叉树的遍历栈的实现 Preorder Traversal Inorder Traversal Postorder Traversal
- 16. 3Sum Closest
- spring mvc ModelAndView 404 错误
- JAVA学习第7天(15-6-25)
- ZOJ Problem Set - 2022||Factorial
- Maven和Ant的区别
- JAVA学习第8天
- freeglut 使用笔记
- CSS使用总结
- 命令模式(Command)
- SRM 635 DIV2
- 错误检测