资源描述
package atm;
import java.io.*;
public class perfect {
public static void main(String[] args) throws IOException {
System.out.println("ATM自动取款机欢迎你的光临!");
System.out.println("请输入您的密码:");
int money = 10000;
int count = 0;
while (count < 3) {
if (login1()) {
System.out.println("欢迎光临\n本ATM自动取款机为你提供如下服务:"
+ "\n1、 余额查询\t2、 取款\t3、 存款\t4 、 转帐\t5、 取卡");
job(money);
} else {
System.out.print("对不起,你输入的密码有误!");
count++;
if (count == 1) {
System.out.println("你已输错密码" + count
+ "次,注意哦,超过3次你的银行卡将被冻结!\n请重新输入:");
}
if (count == 2) {
System.out.println("你已输错密码" + count
+ "次,注意哦,你还有一次输入机会了!\n请重新输入:");
}
if (count == 3) {
System.out.println("你输错密码已达到" + count + "次,你的银行卡已经被冻结。\n"
+ "想要解冻,请带上你本人的身份证到柜台找工作人员核实以解冻,谢谢合作!");
}
}
}
}
public static boolean login1() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
boolean result = false;
if (str.equals("123456"))
result = true;
return result;
}
public static int job(int money) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str; // 定义一个字符串变量
System.out.println("请选择你要的功能:");
str = br.readLine();// 读取用户输入信息
int a = 1; // 对a值进行初始化
a = Integer.parseInt(str);
if (a <= 5 && a >= 1) {
if (a == 1) {
System.out.println("你选择的功能是:余额查询\n");
select(money);
}
if (a == 2) {
System.out.println("你选择的功能是:取款 \n");
outputMoney(money);
select(money);
}
if (a == 3) {
System.out.println("你选择的功能是:存款\n");
inputMoney(money);
select(money);
}
if (a == 4) {
System.out.println("你选择的功能是: 转帐\n");
moveMoney(money);
select(money);
}
while (a == 5) {
System.out.println("你选择的功能是:取卡\n");
x();
select(money);
break;
}
} else {
{
System.out.println("看清楚点咯,请选择正确的选项哦\n");
job(money);
}
}
return a;
}
public static int outputMoney(int x) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入你取款的金额:");
int y = 0;
try {
y = Integer.parseInt(br.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (y % 50 == 0 && x >= y) {
x = x - y;
System.out.println("尊敬的客户,你这次取了" + y + "元,你还有" + x + "元.");
job(x);
}
if (y % 50 == 0 && x < y) {
System.out.println("对不起,你输入的金额已超过你的剩余金额,请重新输入!");
job(x);
}
if (y % 50 != 0) {
System.out.println("对不起,Atm自动取款机只能辨认面额为50倍数的金额");
outputMoney(x);
}
return x;
}
public static int inputMoney(int x) throws IOException {
BufferedReader br3 = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("请输入你的存款金额:");
int y = 0;
try {
y = Integer.parseInt(br3.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (y % 50 == 0 && x >= y) {
x = x + y;
System.out.println("尊敬的客户,你这次存了" + y + "元,你现有" + x + "元了.");
job(x);
}
if (y % 50 != 0) {
System.out.println("对不起,Atm自动取款机只能辨认面额为50倍数的金额");
outputMoney(x);
}
return x;
}
public static int moveMoney(int x) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入你想要转出的金额:");
int y = 0;
try {
y = Integer.parseInt(br.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (y % 50 == 0 && x >= y) {
x = x - y;
System.out.println("尊敬的客户,你这次转出了" + y + "元,你还有" + x + "元了.");
job(x);
}
if (y % 50 == 0 && x < y) {
System.out.println("对不起,你想要转出的金额已超过你的剩余金额,请重新输入!");
job(x);
}
if (y % 50 != 0) {
System.out.println("对不起,Atm自动取款机只能辨认面额为50倍数的金额");
outputMoney(x);
}
return x;
}
public static int select(int money) throws IOException {
{
System.out.println("你的剩余金额为:" + money + "\n");
job(money);
return money;
}
}
public static void x() {
System.out.println("欢迎你的光临,请取回你的磁卡,下次再见!\n");
}
}
展开阅读全文