package atm;
import java.util.Scanner;
public class AccountManager {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
System.out.println("信1705-2 刘晨 20173672");
System.out.println("***************************************************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入您的账号: ");
String nowName = sc.next();
Person p = new Person();
if (p.name.equals(nowName)) {
for (int j = 0; j < 3; j++) {
System.out.println("***************************************************************\r\n" +
"欢迎XXXXXXXX(账户名称)使用中国工商银行自助柜员系统\r\n" +
"**************************************************************** 请输入您的密码:\r\n" +
" \r\n" +
"****************************************************************");
int nowPWD = sc.nextInt();
if (nowPWD == p.pwd) {
System.out.println("登录成功");
flag = true;
break;
} else {
System.out.println("密码错误,您还有" + (2 - i) + "次机会!");
i++;
}
}
} else {
System.out.println("用户名错误,您还有" + (2 - i) + "次机会!");
}
}
return flag;
}
}
int num = 0;
do {
System.out.println("***************************************************************\r\n" +
"欢迎XXXXXXXX(账户名称)使用中国工商银行自助柜员系统\r\n" +
"****************************************************************\r\n" +
"1、存款;\r\n" +
"2、取款;\r\n" +
"3、转账汇款;\r\n" +
"4、修改密码;\r\n" +
"5、查询余额;\r\n" +
"****************************************************************")
num = sc.nextInt();
switch (num) {
case 1:
saveMoney();
break;
case 2:
withdrawals();
break;
case 3:
zhuanzhang();
break;
case 4:
changePassword();
break;
case 5:
findBalance();
break;
default:
System.out.println("您输入数字有误!");
break;
}
} while (num != 0);
//改密码
static void changePassword(hq hquser)throws IOException
{
Scanner in = new Scanner(System.in);
System.out.print("请输入原密码:");
String oldPassword = in.next();
while(!oldPassword.equals(hquser.password))
{
System.out.println("原密码错误!");
System.out.print("请重新输入密码:");
oldPassword = in.next();
}
String new1Password = "1";
String new2Password = "2";
do
{
System.out.print("请输入新密码:");
new1Password = in.next();
ATM a = new ATM();
while(!ATM.checkPassword(new1Password))
{
System.out.println("新密码密码不符合规范!");
System.out.print("请重新输入密码:");
new1Password = in.next();
}
System.out.print("请确认密码:");
new2Password = in.next();
if(!new1Password.equals(new2Password))
System.out.println("两遍密码不一致!");
}while(!new1Password.equals(new2Password));
hquser.password = new1Password;
hq.change(hquser);
System.out.println("密码修改成功!");
}
//查询余额
static void findBalance(String card)throws IOException
{
FileReader fr = new FileReader("UserInfo.txt");
BufferedReader br = new BufferedReader(fr);
while(br.ready())
{
int sum = 0;
String s = br.readLine();
hq hquser = new hq();
hquser.getDate(s);
if(hquser.card.equals(card))
System.out.println("您的余额为:"+hquser.balance);
}
br.close();
fr.close();
}
//存钱
static void saveMoney(hq hquser)throws IOException
{
Scanner in = new Scanner(System.in);
System.out.print("请输入存款金额:");
int money = in.nextInt();
while(true)
{
if(money%100==0 && money>0 && money<=2000)
break;
System.out.println("金额输入不符合规范!");
System.out.print("请重新输入金额:");
money = in.nextInt();
}
hquser.balance = hquser.balance+money;
change(hquser);
FileOutputStream fos = new FileOutputStream("Record.txt",true);
PrintWriter pw = new PrintWriter(fos);
String date;
java.text.DateFormat format1 = new
java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date = format1.format(new Date());
String s = hquser.card+"#"+money+"#"+date;
pw.println(s);
pw.flush();
pw.close();
fos.close();
}
//取钱
static void withdrawals(hq hquser)throws IOException
{
Scanner in = new Scanner(System.in);
System.out.print("请输入取款金额:");
int money = in.nextInt();
while(true)
{
if(hquser.balance>money)
break;
System.out.println("余额不足!");
System.out.print("请重新输入金额:");
money = in.nextInt();
}
while(true)
{
if(money%100==0&&money>0&&money<=2000)
break;
System.out.println("金额输入不符合规范!");
System.out.print("请重新输入金额:");
money = in.nextInt();
}
hquser.balance = hquser.balance-money;
change(hquser);
FileOutputStream fos = new FileOutputStream("Record.txt",true);
PrintWriter pw = new PrintWriter(fos);
String date;
java.text.DateFormat format1 = new
java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date = format1.format(new Date());
String s = hquser.card+"#"+"-"+money+"#"+date;
pw.println(s);
pw.flush();
pw.close();
fos.close();
}
}
}
原文:https://www.cnblogs.com/2205254761qq/p/9697280.html