package zuoye;
import java.util.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class AccountManager {
//数据组
private Account ku[] = new Account[5];
//记录名称
private String Infor = "files/accountinformation.txt";
private String List = "files/accountlist.txt";
private String Today = "2018-9-20";
public static void main1(String[] args){
Account comd[]=new Account[5];
comd[0]=new Account("20173651","zhaojianfeng","777777",66666);
comd[1]=new Account("20173455 ","abcdef","888888",2000);
comd[2]=new Account("20183566","a某","999999",3000);
comd[3]=new Account("20193788 ","b某","666666",2000);
comd[4]=new Account("20203455","c某","555555",1500);
char choise;
System.out.println("***************************************************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入您的账号:");
System.out.println("***************************************************************");
Scanner sc = new Scanner (System.in);
int t = sc.nextInt();
int [] ID={20173492,20173366,20183492,20173492,20203492};
for(int i=0;i<5;i++)
{
if (t!=ID[i])System.out.println("该账号不存在");
else if (t==ID[i])
{ System.out.println("该账号存在");
System.out.println("***************************************************************");
System.out.println(" 欢迎使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入您的密码:");
System.out.println("***************************************************************");
}
}
Scanner ed = new Scanner (System.in);
ed.nextInt();
do {
System.out.println(" 欢迎使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 1.存款");
System.out.println(" 2.取款");
System.out.println(" 3.转账汇款");
System.out.println(" 4.修改密码");
System.out.println(" 5.查询余额");
System.out.println("***************************************************************");
choise=sc.next().charAt(0);
System.out.println();
}while (choise != '6');
}Scanner sc = new Scanner (System.in);
int temp = sc.nextInt();
{
switch(temp)
{
int pass;
assert 1:ku[pass].setoperatetype(1);writefile();fun1(pass);break;
assert 2:ku[pass].setoperatetype(2);writefile();fun2(pass);break;
assert 3:ku[pass].setoperatetype(3);writefile();fun3(pass);break;
assert 4:ku[pass].setoperatetype(4);writefile();fun4(pass);break;
assert 5:ku[pass].setoperatetype(5);writefile();fun5(pass);break;
default:MainWin(pass);
break;
}
public void fun1(int pass) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 请输入存款金额;");
Scanner sc = new Scanner (System.in);
if(sc.hasNext("q"))
FirstWin();
else
{
int JinE = sc.nextInt();//记录金额
if(JinE<=0)
{
System.out.println(" #:输入金额有误");
fun1(pass);
}
else
{
ku[pass].setamount(ku[pass].getamount()+JinE);
ku[pass].setaccountbalance(ku[pass].getaccountbalance()+JinE);
//-----------------------[数据载入文档]
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户存款操作成功。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperadate(Today);
pw.print(" ");
pw.print("SaveMoney");
pw.print(" ");
pw.println(JinE);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
writefile();
//----------------------------------------
MainWin(pass);}
}
}
private void MainWin(int pass) {
// TODO 自动生成的方法存根
}
private void FirstWin() {
// TODO 自动生成的方法存根
}
//取款界面
public void fun2(int pass) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户每日可以支取2万元。");
System.out.println(" 1、100元");
System.out.println(" 2、500元");
System.out.println(" 3、1000元");
System.out.println(" 4、1500元");
System.out.println(" 5、2000元");
System.out.println(" 6、5000元;");
System.out.println(" 7、其他金额");
System.out.println(" 8、退卡");
System.out.println(" 9、返回");
System.out.println("****************************************************************");
System.out.println(" #:请选择");
Scanner sc = new Scanner (System.in);
int choice = sc.nextInt();
switch(choice){
case 1:
{
if(ku[pass].getaccountbalance()<100)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].setamount(ku[pass].getamount()+100);
ku[pass].setaccountbalance(ku[pass].getaccountbalance()-100);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作100元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperadate(Today);
pw.print(" ");
pw.print("getMoney");
pw.print(" ");
pw.println(100);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 2:
{
if(ku[pass].getaccountbalance()<500)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].setamount(ku[pass].getamount()+500);
ku[pass].setaccountbalance(ku[pass].getaccountbalance()-500);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作500元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperadate(Today);
pw.print(" ");
pw.print("getMoney");
pw.print(" ");
pw.println(500);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 3:
{
if(ku[pass].getaccountbalance()<1000)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].setamount(ku[pass].getamount()+1000);
ku[pass].setaccountbalance(ku[pass].getaccountbalance()-1000);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作1000元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print("getMoney");
pw.print(" ");
pw.println(1000);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
//-----------------------------------
MainWin(pass);
}
break;
}
case 4:
{
if(ku[pass].getaccountbalance()<1500)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].setamount(ku[pass].getamount()+1500);
ku[pass].setaccountbalance(ku[pass].getaccountbalance()-1500);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作1500元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperadate(Today);
pw.print(" ");
writefile();
pw.print("getMoney");
pw.print(" ");
pw.println(1500);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
//-----------------------------------
MainWin(pass);
}
break;
}
case 5:
{
if(ku[pass].getaccountbalance()<2000)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].setamount(ku[pass].getamount()+2000);
ku[pass].setaccountbalance(ku[pass].getaccountbalance()-2000);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作2000元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperadate(Today);
pw.print(" ");
writefile();
pw.print("getMoney");
pw.print(" ");
pw.println(2000);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
//-----------------------------------
MainWin(pass);
}
break;
}
case 6:
{
if(ku[pass].getaccountbalance()<5000)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].setamount(ku[pass].getamount()+5000);
ku[pass].setaccountbalance(ku[pass].getaccountbalance()-5000);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作5000元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperadate(Today);
pw.print(" ");
writefile();
pw.print("getMoney");
pw.print(" ");
pw.println(5000);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
//-----------------------------------
MainWin(pass);
}
break;
}
case 7:
{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 请输入取款金额:");
int num = sc.nextInt();
if(ku[pass].getaccountbalance()<num)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].setamount(ku[pass].getamount()+num);
ku[pass].setaccountbalance(ku[pass].getaccountbalance()-num);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作"+num+"元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
writefile();
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperadate(Today);
pw.print(" ");
writefile();
pw.print("getMoney");
pw.print(" ");
pw.println(num);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
//-----------------------------------
MainWin(pass);
}
break;
}
case 8:
{
FirstWin();
break;
}
case 9:
{
MainWin(pass);
break;
}
default:fun2(pass);break;
}
}
//转账汇款界面
public void fun3(int pass) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入转账账户;");
Scanner sc = new Scanner (System.in);
if(sc.hasNext("q"))
FirstWin();
String temp = sc.next();
int tube = 5;//记录账户
for(int i=0;i<5;i++){
if(ku[i].getaccountID().compareTo(temp)==0)
{
tube = i;
break;
}
}
if(tube==5)
{
System.out.println(" #:该用户不存在");
fun3(pass);
}
else
{
fun3_half(pass,tube);
}
}
public void fun3_half(int pass,int pass_to) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入转账金额;");
Scanner sc = new Scanner (System.in);
if(sc.hasNext("q"))
FirstWin();
int JinE= sc.nextInt();
if(JinE>ku[pass].getaccountbalance())
{
System.out.println("账户余额不足");
fun3_half(pass,pass_to);
}
else if(JinE<=0)
fun3_half(pass,pass_to);
else
{
StringBuffer sxw = new StringBuffer(ku[pass_to].getaccountname());
sxw.deleteCharAt(0);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请确认是否向*"+sxw+"转账"+JinE+"元。");
String makesure = sc.next();
if(sc.hasNext("q"))
FirstWin();
if(makesure.compareTo("Y")==0)
{
ku[pass].setaccountbalance(ku[pass].getaccountbalance()-JinE);
ku[pass].setamount(ku[pass].getamount()+JinE);
ku[pass_to].setaccountbalance(ku[pass_to].getaccountbalance()+JinE);
ku[pass_to].setamount(ku[pass_to].getamount()+JinE);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 当前账户向*"+sxw+"转账"+JinE+"元。");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
}
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperatedate(Today);
pw.print(" ");
writefile();
pw.print("RemoveMoney");
pw.print(" ");
pw.println(JinE);
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
//-----------------------------------
MainWin(pass);
}
}
//修改密码界面
public void fun4(int pass) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
String str1,str2;
System.out.println(" 请输入当前密码: ");
Scanner sc = new Scanner (System.in);
str1 = sc.next();
if(sc.hasNext("q"))
FirstWin();
if(ku[pass].getaccountpassword().compareTo(str1)==0)
{
System.out.println(" 请输入修改密码:");
str1 = sc.next();
if(sc.hasNext("q"))
FirstWin();
System.out.println(" 请输入确认密码:");
str2 = sc.next();
if(sc.hasNext("q"))
FirstWin();
if(str1.compareTo(str2)==0)
{
ku[pass].setaccountpassword(str1);
writefile();
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 当前账户密码修改成功");
//----------------------------------------------------<以下为文件更新阶段
Scanner scs = new Scanner (new FileReader(List));
PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
while(!scs.hasNext("ENDOFTHISFILE"))//将 List 文件里的数据临时储存在 LinShi 文件下
{
pws.println(scs.nextLine());
}
pws.println(scs.nextLine());
pws.close();
Scanner scp = new Scanner (new FileReader("files/LinShi"));
PrintWriter pw = new PrintWriter (new FileWriter(List));
pw.print(ku[pass].getaccountID());
pw.print(" ");
pw.print(Today);
ku[pass].setoperatedate(Today);
pw.print(" ");
writefile();
pw.print("ChangePassword");
pw.print(" ");
pw.println("**********");
while(!scp.hasNext("ENDOFTHISFILE"))
{
pw.println(scp.nextLine());
}
pw.println(scp.nextLine());
pw.close();
//-----------------------------------
MainWin(pass);
}
else
{
System.out.println(" 修改密码与确认密码不一致");
fun4(pass);
}
}
else
{
System.out.println(" 当前密码录入错误");
fun4(pass);
}
}
//查询金额界面
public void fun5(int pass) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 当前账户余额为:"+ku[pass].getaccountbalance()+"元");
System.out.println(" 账户清单信息为:");
int sx = 1;
Scanner sl = new Scanner (new File(List));
while(true)
{
String str3 = sl.next();//账户
if(str3.compareTo("ENDOFTHISFILE")==0)
break;
String str1 = sl.next();//日期
String str2 = sl.next();//操作类型
String dateofthis = sl.next();//操作金额
if(ku[pass].getaccountID().compareTo(str3)==0)
{
System.out.println(sx+"、"+str1+" "+str2+" "+dateofthis);
sx++;
}
}
MainWin(pass);
}
//----------------<构造函数>---------------//
public AccountManager() throws FileNotFoundException{
for(int i=0;i<5;i++)
ku[i] = new Account();
readfile();
}
//写入
public void writefile() throws IOException{
FileWriter fr = new FileWriter(Infor);
BufferedWriter bw = new BufferedWriter(fr);
PrintWriter fl = new PrintWriter(bw);
for(int i =0;i<5;i++)
{
fl.print(ku[i].getaccountID());
fl.print(' ');
fl.print(ku[i].getaccountname());
fl.print(' ');
fl.print(ku[i].getoperatedate());
fl.print(' ');
fl.print(ku[i].getoperatetype());
fl.print(' ');
fl.print(ku[i].getaccountpassword());
fl.print(' ');
fl.print(ku[i].getaccountbalance());
fl.print(' ');
fl.print(ku[i].getamount());
fl.print("\n");
}
fl.close();
}
//读入
public void readfile() throws FileNotFoundException{
Scanner fl = new Scanner(new File(Infor));
for(int i=0;i<5;i++)
ku[i].set(fl.next(),fl.next(),fl.next(),fl.nextInt(),fl.next(),fl.nextInt(),fl.nextInt());
}
//----------------<主函数>-----------------//
public static void main(String[] args) throws IOException {
AccountManager ap = new AccountManager();
ap.FirstWin();
}
}
}