ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ATM机

2020-09-23 04:32:40  阅读:200  来源: 互联网

标签:String ATM System bufferedWriter println new out


package student;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
//苏宁 20193964 信1905-1班
public class Account {
private static String accountID;
private static String accountname;
private static String operatedate;
private static int operatetype;
private static String accountpassword;
private static int accountbalance;
private static int amount;
public static class AccountManager
{
public static void l()//流水记录完成
{
Date date = new Date();
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
operatedate=ft.format(date);
try{
File file = new File("accountlist.txt");
FileOutputStream er = null;
er = new FileOutputStream(file,true);
OutputStreamWriter osw = new OutputStreamWriter(er, "UTF-8");
osw.write(accountID);
osw.write("\r\n");
osw.write(accountname);
osw.write("\r\n");
osw.write(operatedate);
osw.write("\r\n");
String q4;
q4=String.valueOf(operatetype);
osw.write(q4);
osw.write("\r\n");
q4=String.valueOf(amount);
osw.write(q4);
osw.write("\r\n");
osw.close();
}catch (Exception e) {
e.printStackTrace();
}
}
private static void r() throws IOException//账号登录完成
{
Scanner k=new Scanner(System.in);
String accountID2=k.next();
try(BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("accountinformation.txt"),"UTF-8")); )
{
for(int u=0;;u++)
{
String y;
accountID=br.readLine();
accountname=br.readLine();
accountpassword=br.readLine();
y=br.readLine();
accountbalance = Integer.valueOf(y).intValue();
if(accountID2.equals(accountID))
{
b();
}
if(u==4)
{
System.out.println("未查找到账户");
a();
break;
}
}
br.close();
}
}
public static void a() throws IOException//账号输入页面完成
{
System.out.println("***************************************************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入您的账号: ");
System.out.println("");
System.out.println("***************************************************************");
r();
}
public static void b() throws IOException//密码输入页面完成
{
String sr;
Scanner k=new Scanner(System.in);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入您的密码: ");
System.out.println("");
System.out.println("***************************************************************");
for(int y=0;y<3;y++)
{
sr=k.next();
if(sr.equals(accountpassword)) {
c();
}else {
System.out.println("密码录入错误");
System.out.print("请重新输入:");
}
}
System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理");
System.out.print("已返回主页面");
main(null);
}
public static void c() throws IOException//主页面完成
{
int a;
Scanner k=new Scanner(System.in);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
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("");
System.out.println("***************************************************************");
a=k.nextInt();
switch(a)
{
case 1:
c1();
break;
case 2:
c2();
break;
case 3:
c3();
break;
case 4:
c4();
break;
case 5:
c5();
break;
default:
System.out.println("输入错误,重新输入");
c();
}
}
public static void c1() throws IOException//存款,流水记录完成
{
Double a;
Scanner k=new Scanner(System.in);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入存款金额; ");
System.out.println("***************************************************************");
a=k.nextDouble();
if(a%1==0) {
String ty;
accountbalance+=a;
w();
amount = new Double(a).intValue();
operatetype=1;
l();
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 当前账户存款操作成功。 ");
System.out.println(" 当前账户余额为:"+accountbalance+"元 ");
System.out.println("***************************************************************");
System.out.println("输入字母“q”,则返回系统输入账号界面");
ty=k.next();
if(ty=="q")
{
main(null);
}else {
System.out.println("返回主页面");
main(null);
}
}else
{
System.out.println("输入金额有误,返回存款界面");
c1();
}
}
public static void c2() throws IOException //取款,流水记录完成
{
Scanner k=new Scanner(System.in);
int y;
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
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("***************************************************************");
y=k.nextInt();
switch(y)
{
case 1:
if(accountbalance>=100)
{
amount=100;
accountbalance-=amount;
c22();
}else {
c23();
}
break;
case 2:
if(accountbalance>=500)
{
amount=500;
accountbalance-=amount;
c22();
}else {
c23();
}
break;
case 3:
if(accountbalance>=1000)
{
amount=1000;
accountbalance-=amount;
c22();
}else {
c23();
}
break;
case 4:
if(accountbalance>=1500)
{
amount=1500;
accountbalance-=amount;
c22();
}else {
c23();
}
break;
case 5:
if(accountbalance>=2000)
{
amount=2000;
accountbalance-=amount;
c22();
}else {
c23();
}
case 6:
if(accountbalance>=5000)
{
amount=5000;
accountbalance-=amount;
c22();
}else {
c23();
}
case 7:
int we;
we=k.nextInt();
if(accountbalance>=we)
{
int a;
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"(账户名称)使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入存款金额;");
System.out.println("");
System.out.println("***************************************************************");
amount=we;
accountbalance-=amount;
c22();
}else {
c23();
}
case 8:
a();
break;
case 9:
c();
break;
default:
System.out.println("输入错误,重新输入");
c2();
}
}
public static void c22() throws IOException//取款成功页面完成
{
w();
operatetype=2;
l();
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"(账户名称)使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 当前账户取款"+amount+"操作成功。");
System.out.println(" 当前账户余额为:"+accountbalance+" ");
System.out.println("***************************************************************");
System.out.println("返回主界面");
main(null);
}
public static void w() throws IOException //账户余额保存完成
{
String[] w1=new String[5];
String[] w2=new String[5];
String[] w3=new String[5];
String[] w4=new String[5];
try(BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("accountinformation.txt"),"UTF-8")); )
{
for(int u=0;u<5;u++)
{
w1[u]=br.readLine();
w2[u]=br.readLine();
w3[u]=br.readLine();
w4[u]=br.readLine();
}
br.close();
}
File file=new File("accountinformation.txt");
file.delete();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
for(int u=0;u<5;u++)
{
bufferedWriter.write(w1[u]);
bufferedWriter.newLine();
bufferedWriter.write(w2[u]);
bufferedWriter.newLine();
bufferedWriter.write(w3[u]);
bufferedWriter.newLine();
if(w1[u].equals(accountID))
{
String y;
y =String.valueOf(accountbalance);
bufferedWriter.write(y);
bufferedWriter.newLine();
}else
{
bufferedWriter.write(w4[u]);
bufferedWriter.newLine();
}
}
bufferedWriter.flush();
bufferedWriter.close();
}
public static void c23() throws IOException//取款余额不足页面完成
{
System.out.println("余额不足,重新输入");

}
public static void c3() throws IOException //转账页面完成
{
Scanner k=new Scanner(System.in);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入转账账户: ");
System.out.println("");
System.out.println("***************************************************************");
String tr=k.next();
try(BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("accountinformation.txt"),"UTF-8")); )
{
String q1;
String q2;
String q3;
String q4;
for(int u=0;;u++)//查找转账账户
{
q1=br.readLine();
q2=br.readLine();
q3=br.readLine();
q4=br.readLine();
if(tr.equals(q1))//找到转账账户
{
int sr;
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入转账金额: ");
System.out.println("");
System.out.println("***************************************************************");
sr=k.nextInt();
amount=sr;
if(sr<=accountbalance)//余额判断
{
String h,m;
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请确认"+q2+"转账 "+amount+"元 ");
System.out.println("");
System.out.println("***************************************************************");
System.out.println("“Y”表示确认转账,“N”表示不确认转账");
h=k.next();
m="Y";
if(h.equals(m))//转账确认后
{
accountbalance-=amount;
w();//本账户余额保存
int rs;//转账账户余额计算
rs = Integer.valueOf(q4).intValue();
rs+=amount;
q4=String.valueOf(rs);
String[] w1=new String[5];//下面是转账账号余额保存
String[] w2=new String[5];
String[] w3=new String[5];
String[] w4=new String[5];
try(BufferedReader eg=new BufferedReader(new InputStreamReader(new FileInputStream("accountinformation.txt"),"UTF-8")); )
{
for(int v=0;v<5;v++)
{
w1[v]=eg.readLine();
w2[v]=eg.readLine();
w3[v]=eg.readLine();
w4[v]=eg.readLine();
}
eg.close();
}
File file=new File("accountinformation.txt");
file.delete();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
for(int v=0;v<5;v++)
{
bufferedWriter.write(w1[v]);
bufferedWriter.newLine();
bufferedWriter.write(w2[v]);
bufferedWriter.newLine();
bufferedWriter.write(w3[v]);
bufferedWriter.newLine();
if(w1[v].equals(q1))
{
bufferedWriter.write(q4);
bufferedWriter.newLine();
}else
{
bufferedWriter.write(w4[v]);
bufferedWriter.newLine();
}
}
bufferedWriter.flush();
bufferedWriter.close();
operatetype=3;
l();
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 当前账户向"+q1+"成功转账"+amount+"元。 ");
System.out.println(" 余额:"+accountbalance+";");
System.out.println("***************************************************************");
System.out.println("返回主页面");
a();
}else
{
System.out.println("已取消");
a();
}
}else
{
System.out.println("余额不足");
a();
}
}
if(u==4)
{
System.out.println("未查找到账户");
c3();
}
}
}
}
public static void c4() throws IOException//修改密码完成
{
String sr,jk;
Scanner k=new Scanner(System.in);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 请输入当前密码: ");
System.out.println(" 请输入修改密码: ");
System.out.println(" 请输入确认密码: ");
System.out.println("");
System.out.println("***************************************************************");
sr=k.next();
if(sr.equals(accountpassword)) {
sr=k.next();
jk=k.next();
for(int u=0;;u++)
{
if(sr.equals(jk))
{
accountpassword=jk;
w2();
operatetype=4;
l();
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 当前账号修改密码成功 ");
System.out.println("***************************************************************");
System.out.println("返回主页面");
a();
break;
}else {
System.out.println("修改密码和确认密码不一致,重新输入");
}
}
}else {
System.out.println("密码错误");
c4();
}
}
public static void w2() throws IOException//保存修改密码完成
{
String[] w1=new String[5];
String[] w2=new String[5];
String[] w3=new String[5];
String[] w4=new String[5];
try(BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("accountinformation.txt"),"UTF-8")); )
{
for(int u=0;u<5;u++)
{
w1[u]=br.readLine();
w2[u]=br.readLine();
w3[u]=br.readLine();
w4[u]=br.readLine();
}
br.close();
}
File file=new File("accountinformation.txt");
file.delete();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
for(int u=0;u<5;u++)
{
bufferedWriter.write(w1[u]);
bufferedWriter.newLine();
bufferedWriter.write(w2[u]);
bufferedWriter.newLine();
if(w1[u].equals(accountID))
{
bufferedWriter.write(accountpassword);
bufferedWriter.newLine();
}else
{
bufferedWriter.write(w3[u]);
bufferedWriter.newLine();
}
bufferedWriter.write(w4[u]);
bufferedWriter.newLine();
}
bufferedWriter.flush();
bufferedWriter.close();
}
public static void c5() throws IOException //流水查看完成
{
amount=0;
operatetype=5;
l();
System.out.println("***************************************************************");
System.out.println(" 欢迎"+accountname+"使用中国工商银行自助柜员系统 ");
System.out.println("***************************************************************");
System.out.println(" 当前账户余额为:"+accountbalance+" ");
System.out.println(" 账户清单信息为: ");
try(BufferedReader yr=new BufferedReader(new InputStreamReader(new FileInputStream("accountlist.txt"),"UTF-8")); )
{
String c1;
String c2;
String c3;
String c4;
String c5;
for(int u=1;;u++)
{
if((c1=yr.readLine())==null) break;
c2=yr.readLine();
c3=yr.readLine();
c4=yr.readLine();
c5=yr.readLine();
if(c1.equals(accountID))
{
System.out.print(u+" 操作日期:");
System.out.print(c3+" ");
int sda;
sda = Integer.valueOf(c4).intValue();
switch(sda)
{
case 1:
System.out.print("存款 ");
break;
case 2:
System.out.print("取款 ");
break;
case 3:
System.out.print("转账汇款 ");
break;
case 4:
System.out.print("修改密码 ");
break;
case 5:
System.out.print("查询余额 ");
break;
}
System.out.println(c5+" ");
}
}
System.out.println("打印完成;");
System.out.println("***************************************************************");
}

}
}
public static void main(String[] args) throws IOException {
AccountManager.a();
}
}

标签:String,ATM,System,bufferedWriter,println,new,out
来源: https://www.cnblogs.com/da48/p/13715913.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有