[size=medium][size=medium][/size][color=red][/color][align=center][/align]package com.lovo;
import javax.swing.JOptionPane;
/**
* ATM提款機
* @author WenChuan
*
*/
public class Atm {
public static void main(String[] args) {
// 默认原有的钱
int money = 1000;
// 输入的次数
int counter = 0;
//登陸介面
JOptionPane.showMessageDialog(null, "欢迎使用ATM提款机");
for (counter = 0; counter < 10; counter++) {
/*
* 用戶名和密碼的判斷
*
* */
String userName = JOptionPane.showInputDialog("请输入用户名:");
String passWord = JOptionPane.showInputDialog("请输入密码:");
int password = Integer.parseInt(passWord);
if (userName.equals("abc") && password == 123) {
JOptionPane.showMessageDialog(null, "登陆成功");
break;
} else {
JOptionPane.showMessageDialog(null, "用户名或密码不对,请重新输入");
}
while (counter == 2) {
JOptionPane.showMessageDialog(null, "你是非法用户,吞卡中、、、、");
System.exit(counter);
}
}
/**
* 進入系統操作!!
*/
while (counter < 3) {
String string = JOptionPane.showInputDialog("1-存钱,2-取款,3-查询,4-退出");
int select = Integer.parseInt(string);
/*
* 存款
*
* */
if (select == 1) {
String m = JOptionPane.showInputDialog("请输入存款金额:");
int money3 = Integer.parseInt(m);
money = money + money3;
JOptionPane.showMessageDialog(null, "存款成功,现在金额是" + money + "元");
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
}
/*
* 取款
*
* */
else if (select == 2) {
while (true) {
String m1 = JOptionPane.showInputDialog("请输入取款金额");
int money2 = Integer.parseInt(m1);
if (money >= money2) {
money = money - money2;
JOptionPane.showMessageDialog(null, "取款成功,现在金额是"
+ money + "元");
break;
} else {
JOptionPane.showMessageDialog(null, "对不起,余额不足,请重新输入");
continue;
}
}
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
}
/*
* 查詢
*
* */
else if (select == 3) {
JOptionPane.showMessageDialog(null, "你好!你的余额是" + money);
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
} else if (select == 4) {
break;
} else {
JOptionPane.showMessageDialog(null, "你输入有误,请重新输入");
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
}
}
}
}[/size]
import javax.swing.JOptionPane;
/**
* ATM提款機
* @author WenChuan
*
*/
public class Atm {
public static void main(String[] args) {
// 默认原有的钱
int money = 1000;
// 输入的次数
int counter = 0;
//登陸介面
JOptionPane.showMessageDialog(null, "欢迎使用ATM提款机");
for (counter = 0; counter < 10; counter++) {
/*
* 用戶名和密碼的判斷
*
* */
String userName = JOptionPane.showInputDialog("请输入用户名:");
String passWord = JOptionPane.showInputDialog("请输入密码:");
int password = Integer.parseInt(passWord);
if (userName.equals("abc") && password == 123) {
JOptionPane.showMessageDialog(null, "登陆成功");
break;
} else {
JOptionPane.showMessageDialog(null, "用户名或密码不对,请重新输入");
}
while (counter == 2) {
JOptionPane.showMessageDialog(null, "你是非法用户,吞卡中、、、、");
System.exit(counter);
}
}
/**
* 進入系統操作!!
*/
while (counter < 3) {
String string = JOptionPane.showInputDialog("1-存钱,2-取款,3-查询,4-退出");
int select = Integer.parseInt(string);
/*
* 存款
*
* */
if (select == 1) {
String m = JOptionPane.showInputDialog("请输入存款金额:");
int money3 = Integer.parseInt(m);
money = money + money3;
JOptionPane.showMessageDialog(null, "存款成功,现在金额是" + money + "元");
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
}
/*
* 取款
*
* */
else if (select == 2) {
while (true) {
String m1 = JOptionPane.showInputDialog("请输入取款金额");
int money2 = Integer.parseInt(m1);
if (money >= money2) {
money = money - money2;
JOptionPane.showMessageDialog(null, "取款成功,现在金额是"
+ money + "元");
break;
} else {
JOptionPane.showMessageDialog(null, "对不起,余额不足,请重新输入");
continue;
}
}
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
}
/*
* 查詢
*
* */
else if (select == 3) {
JOptionPane.showMessageDialog(null, "你好!你的余额是" + money);
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
} else if (select == 4) {
break;
} else {
JOptionPane.showMessageDialog(null, "你输入有误,请重新输入");
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
}
}
}
}[/size]