package Tests;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;
import java.util.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;
import java.util.*;
public class AccountManager {
private static Scanner can=new Scanner(System.in);
private Vector<Account> map=new Vector<Account>();
private Vector<Account> maplist=new Vector<Account>();
private final String szM[]=new String[]{"存款","取款","转账","修改密码","查询"};
private Iterator<Account> it;
private String cnum;
private int go;
private int index;
private int an;
private Account me=new Account();
public static void main(String[] args) {
AccountManager a=new AccountManager();
try {
a.insert_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
a.start();
}
public void start()
{
go=3;
index=0;
an=0;
System.out.println("***************************************************************");
System.out.println("\t欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入您的账号:");
if(can.hasNext())
{
cnum=can.next();
}
if(cnum.length()==8)
{
// TODO 自动生成的方法存根
if(isfind(cnum))
{
index=lookp(cnum)-1;
showpass();
}
else
{
System.out.println("\t没有找到相关账户信息,请重新输入");
start();
}
}
else
{
System.out.println("\t输入的账户信息不是八位数,请重新输入");
start();
}
}
public void showpass()
{
try {
insert_2();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入您的密码:");
if(can.hasNext())
{
cnum=can.next();
}
if(cnum.length()==6)
{
if(Integer.parseInt(cnum)==me.getAccountpassword())
{
insystem();
}
else
{
if(go>0)
{
System.out.println("\t密码错误,请重新输入,还剩"+go+"次机会重新输入");
showpass();
go--;
}
else
{
System.out.println("\t密码错误输入次数过多,返回账号输入菜单");
start();
}
}
}
else
{
System.out.println("\t输入的密码信息不是六位数,请重新输入");
showpass();
}
}
public void insystem()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t1.存款");
System.out.println("\t2.取款");
System.out.println("\t3.转账汇款");
System.out.println("\t4.修改密码");
System.out.println("\t5.查询余额");
System.out.println("\tq.登录菜单");
int type=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
else
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else
{
System.out.println("输入错误,请重新输入");
insystem();
return;
}
}
func(type);
private Vector<Account> map=new Vector<Account>();
private Vector<Account> maplist=new Vector<Account>();
private final String szM[]=new String[]{"存款","取款","转账","修改密码","查询"};
private Iterator<Account> it;
private String cnum;
private int go;
private int index;
private int an;
private Account me=new Account();
public static void main(String[] args) {
AccountManager a=new AccountManager();
try {
a.insert_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
a.start();
}
public void start()
{
go=3;
index=0;
an=0;
System.out.println("***************************************************************");
System.out.println("\t欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入您的账号:");
if(can.hasNext())
{
cnum=can.next();
}
if(cnum.length()==8)
{
// TODO 自动生成的方法存根
if(isfind(cnum))
{
index=lookp(cnum)-1;
showpass();
}
else
{
System.out.println("\t没有找到相关账户信息,请重新输入");
start();
}
}
else
{
System.out.println("\t输入的账户信息不是八位数,请重新输入");
start();
}
}
public void showpass()
{
try {
insert_2();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入您的密码:");
if(can.hasNext())
{
cnum=can.next();
}
if(cnum.length()==6)
{
if(Integer.parseInt(cnum)==me.getAccountpassword())
{
insystem();
}
else
{
if(go>0)
{
System.out.println("\t密码错误,请重新输入,还剩"+go+"次机会重新输入");
showpass();
go--;
}
else
{
System.out.println("\t密码错误输入次数过多,返回账号输入菜单");
start();
}
}
}
else
{
System.out.println("\t输入的密码信息不是六位数,请重新输入");
showpass();
}
}
public void insystem()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t1.存款");
System.out.println("\t2.取款");
System.out.println("\t3.转账汇款");
System.out.println("\t4.修改密码");
System.out.println("\t5.查询余额");
System.out.println("\tq.登录菜单");
int type=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
else
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else
{
System.out.println("输入错误,请重新输入");
insystem();
return;
}
}
func(type);
}
public void func(int type)
{
if(type==1)
{
deposit_1();
}
else if(type==2)
{
draw();
}
else if(type==3)
{
transfer();
}
else if(type==4)
{
change();
}
else if(type==5)
{
inquiry();
}
}
public void transfer()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入你要转账的账号:");
String type=null;
if(can.hasNext())
{
type=can.next();
}
if((an=lookp(type)-1)!=-1)
{
jiner();
}
else
{
System.out.println("\t查无此账号");
}
}
public void jiner()
{
int c=0;
System.out.println("\t请输入你要转账的金额:");
if(can.hasNextInt())
{
c=can.nextInt();
}
if(me.getAccountbalance()>=c)
{
Account ss=new Account();
me.setAccountbalance(me.getAccountbalance()-c);
me.setAmount(me.getAmount()-c);
me.setOperatetype(3);
ss=me;
map.get(an).setAccountbalance(map.get(an).getAccountbalance()+c);
map.get(an).setAmount(map.get(an).getAmount()+c);
map.get(an).setOperatetype(1);
map.setElementAt(ss, index);
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户向"+map.get(an).getAccountname()+"成功转账"+c+"元。");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
insystem();
}
else
{
System.out.println("金额不够,不能转");
transfer();
}
}
public void change()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入你原来的密码:");
int type=0,g_old=0,g_new=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
if(type==me.getAccountpassword())
{
System.out.println("\t请输入你要修改的密码:");
if(can.hasNextInt())
{
g_old=can.nextInt();
}
if(!(g_old>=100000&&g_old<=999999))
{
System.out.println("\t密码输入格式错误,请重新输入");
change();
return;
}
System.out.println("\t请再次你输入你要修改的密码:");
if(can.hasNextInt())
{
g_new=can.nextInt();
}
if(g_new==g_old)
{
Account ss=new Account();
me.setAccountpassword(g_old);
me.setOperatetype(4);
ss=me;
map.setElementAt(ss, index);
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t密码修改成功");
System.out.println("***************************************************************\n");
System.out.println("\t按q输入回车回到账号输入菜单,按其他任意键回到主菜单\n");
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面\n");
start();
return;
}
else insystem();
}
}
}
}
public void inquiry()
{
me.setOperatetype(5);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("\t账号清单信息为:");
it=maplist.iterator();
int i=1;
Account st=new Account();
while(it.hasNext())
{
st=it.next();
if(st.getAccountID().equals(me.getAccountID()))
{
System.out.println("\t"+i+"、"+st.getOperatedate()+" "+szM[st.getOperatetype()-1]+" "+st.getAmount());
i++;
}
}
if(i==1)
System.out.println("用户尚无操作");
System.out.println("***************************************************************\n");
Account ss=new Account();
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
//1
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
insystem();
}
public void draw()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户每日可以支取2万元。");
System.out.println("\t1.100元");
System.out.println("\t2.500元");
System.out.println("\t3.1000元");
System.out.println("\t4.1500元");
System.out.println("\t5.2000元");
System.out.println("\t6.5000元");
System.out.println("\t7.其他金额");
System.out.println("\t8.退卡");
System.out.println("\t9.返回");
int type=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
deposit(type);
}
public void deposit(int type)
{
boolean g_test=false;
Account ss=new Account();
if(type==1)
{
if(me.getAccountbalance()>=100)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-100);
me.setAmount(me.getAmount()-100);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==2)
{
if(me.getAccountbalance()>=500)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-500);
me.setAmount(me.getAmount()-500);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==3)
{
if(me.getAccountbalance()>=1000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-1000);
me.setAmount(me.getAmount()-1000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==4)
{
if(me.getAccountbalance()>=1500)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-1500);
me.setAmount(me.getAmount()-1500);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==5)
{
if(me.getAccountbalance()>=2000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-2000);
me.setAmount(me.getAmount()-2000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==6)
{
if(me.getAccountbalance()>=5000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-5000);
me.setAmount(me.getAmount()-5000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==7)
{
int num=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
if(me.getAccountbalance()>=num)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-num);
me.setAmount(me.getAmount()-num);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==8)
{
System.out.println("\t8.退卡成功");
start();
return;
}
else if(type==9)
{
insystem();
return;
}
if(g_test)
{
me.setOperatetype(2);
ss.setOperatetype(2);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户取款成功");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("\t输入q退出到账号菜单,按其他任意键回到主菜单\n");
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else insystem();
}
}
}
public void deposit_1()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入存款金额:");
int num=0;
if(can.hasNextInt())
{
num=can.nextInt();
}
else
{
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else
{
System.out.println("输入错误,请重新输入");
deposit_1();
}
}
}
if(num>0)
{
Account ss=new Account();
me.setAccountbalance(me.getAccountbalance()+num);
me.setAmount(me.getAmount()+num);
ss=me;
map.setElementAt(ss, index);
achieve();
}
else
{
System.out.println("输入错误,请重新输入");
deposit_1();
}
}
void achieve()
{
me.setOperatetype(1);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户存款成功");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
System.out.println("\t输入q退出到账号菜单,按其他任意键回到主菜单\n");
//1
Account ss=new Account();
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else insystem();
}
}
public void insert_1() throws IOException
{
File a=new File("accountinformation.txt");
FileInputStream b = new FileInputStream(a);
map.clear();
InputStreamReader c=new InputStreamReader(b,"UTF-8");
{
BufferedReader bufr =new BufferedReader(c);
String line = null;
boolean g_tr=false;
while((line = bufr.readLine())!=null){
if(!g_tr)
{
g_tr=true;
continue;
}
Account st=new Account();
String ook[]=line.split(" "); //字符串变成字符串数组
st.set(ook[0],ook[1], Integer.parseInt(ook[2]),Integer.parseInt(ook[3]));
map.add(st);
}
bufr.close();
//System.out.println(sb.toString());
}
c.close();
b.close();
}
public void insert_2() throws IOException
{
File a=new File("accountlist.txt");
FileInputStream b = new FileInputStream(a);
InputStreamReader c=new InputStreamReader(b,"UTF-8");
{
BufferedReader bufr =new BufferedReader(c);
String line = null;
maplist.clear();
boolean g_tr=false;
String ostr="",temp_str="";
while((line = bufr.readLine())!=null){
if(!g_tr)
{
g_tr=true;
continue;
}
Account st=new Account();
String ook[]=line.split(" ");
st.setAccountID(ook[3]);
st.set_1(ook[0],Integer.parseInt(ook[1]),Integer.parseInt(ook[2]));
if(me.getAccountID().equals(ook[3]))
{
ostr=ook[0];
me.setAmount(Integer.parseInt(ook[1]));
me.setOperatedate(ook[0]);
}
maplist.add(st);
}
Date dt = new Date(); //获取时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //对时间格式化
temp_str=sdf.format(dt);
if(!ostr.equals(temp_str))
{
me.setAmount(0);
me.setOperatedate(temp_str);
}
bufr.close();
}
c.close();
b.close();
}
public void output_1() throws IOException
{
Account st=new Account();
File a=new File("accountinformation.txt");
FileOutputStream b = new FileOutputStream(a);
OutputStreamWriter c=new OutputStreamWriter(b,"UTF-8");
it=map.iterator();
while(it.hasNext())
{
c.append("\r\n");
st=it.next();
c.append(st.getAccountID()+" "+st.getAccountname()+" "+st.getAccountpassword()+" "+st.getAccountbalance());
}
c.close();
b.close();
}
public void output_2() throws IOException
{
File a=new File("accountlist.txt");
FileOutputStream b = new FileOutputStream(a,true);
String temp_str="";
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
temp_str=sdf.format(dt);
OutputStreamWriter c=new OutputStreamWriter(b,"UTF-8");
{
c.append("\r\n");
c.append(temp_str+" "+me.getAmount()+" "+me.getOperatetype()+" "+me.getAccountID());
}
c.close();
b.close();
}
//-----------------------------
public int lookp(String xuehao)
{
Account st=new Account();
int i=0;
it=map.iterator();
while(it.hasNext())
{
i++;
st=it.next();
if(st.getAccountID().equals(xuehao))
break;
}
return i;
}
public boolean isfind(String xuehao)
{
Account st=new Account();
it=map.iterator();
boolean flag=false;
while(it.hasNext())
{
st=it.next();
if(st.getAccountID().equals(xuehao))
{
me=st;
flag=true;
break;
}
}
return flag;
}
public void func(int type)
{
if(type==1)
{
deposit_1();
}
else if(type==2)
{
draw();
}
else if(type==3)
{
transfer();
}
else if(type==4)
{
change();
}
else if(type==5)
{
inquiry();
}
}
public void transfer()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入你要转账的账号:");
String type=null;
if(can.hasNext())
{
type=can.next();
}
if((an=lookp(type)-1)!=-1)
{
jiner();
}
else
{
System.out.println("\t查无此账号");
}
}
public void jiner()
{
int c=0;
System.out.println("\t请输入你要转账的金额:");
if(can.hasNextInt())
{
c=can.nextInt();
}
if(me.getAccountbalance()>=c)
{
Account ss=new Account();
me.setAccountbalance(me.getAccountbalance()-c);
me.setAmount(me.getAmount()-c);
me.setOperatetype(3);
ss=me;
map.get(an).setAccountbalance(map.get(an).getAccountbalance()+c);
map.get(an).setAmount(map.get(an).getAmount()+c);
map.get(an).setOperatetype(1);
map.setElementAt(ss, index);
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户向"+map.get(an).getAccountname()+"成功转账"+c+"元。");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
insystem();
}
else
{
System.out.println("金额不够,不能转");
transfer();
}
}
public void change()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入你原来的密码:");
int type=0,g_old=0,g_new=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
if(type==me.getAccountpassword())
{
System.out.println("\t请输入你要修改的密码:");
if(can.hasNextInt())
{
g_old=can.nextInt();
}
if(!(g_old>=100000&&g_old<=999999))
{
System.out.println("\t密码输入格式错误,请重新输入");
change();
return;
}
System.out.println("\t请再次你输入你要修改的密码:");
if(can.hasNextInt())
{
g_new=can.nextInt();
}
if(g_new==g_old)
{
Account ss=new Account();
me.setAccountpassword(g_old);
me.setOperatetype(4);
ss=me;
map.setElementAt(ss, index);
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t密码修改成功");
System.out.println("***************************************************************\n");
System.out.println("\t按q输入回车回到账号输入菜单,按其他任意键回到主菜单\n");
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面\n");
start();
return;
}
else insystem();
}
}
}
}
public void inquiry()
{
me.setOperatetype(5);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("\t账号清单信息为:");
it=maplist.iterator();
int i=1;
Account st=new Account();
while(it.hasNext())
{
st=it.next();
if(st.getAccountID().equals(me.getAccountID()))
{
System.out.println("\t"+i+"、"+st.getOperatedate()+" "+szM[st.getOperatetype()-1]+" "+st.getAmount());
i++;
}
}
if(i==1)
System.out.println("用户尚无操作");
System.out.println("***************************************************************\n");
Account ss=new Account();
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
//1
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
insystem();
}
public void draw()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户每日可以支取2万元。");
System.out.println("\t1.100元");
System.out.println("\t2.500元");
System.out.println("\t3.1000元");
System.out.println("\t4.1500元");
System.out.println("\t5.2000元");
System.out.println("\t6.5000元");
System.out.println("\t7.其他金额");
System.out.println("\t8.退卡");
System.out.println("\t9.返回");
int type=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
deposit(type);
}
public void deposit(int type)
{
boolean g_test=false;
Account ss=new Account();
if(type==1)
{
if(me.getAccountbalance()>=100)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-100);
me.setAmount(me.getAmount()-100);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==2)
{
if(me.getAccountbalance()>=500)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-500);
me.setAmount(me.getAmount()-500);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==3)
{
if(me.getAccountbalance()>=1000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-1000);
me.setAmount(me.getAmount()-1000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==4)
{
if(me.getAccountbalance()>=1500)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-1500);
me.setAmount(me.getAmount()-1500);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==5)
{
if(me.getAccountbalance()>=2000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-2000);
me.setAmount(me.getAmount()-2000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==6)
{
if(me.getAccountbalance()>=5000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-5000);
me.setAmount(me.getAmount()-5000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==7)
{
int num=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
if(me.getAccountbalance()>=num)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-num);
me.setAmount(me.getAmount()-num);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==8)
{
System.out.println("\t8.退卡成功");
start();
return;
}
else if(type==9)
{
insystem();
return;
}
if(g_test)
{
me.setOperatetype(2);
ss.setOperatetype(2);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户取款成功");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("\t输入q退出到账号菜单,按其他任意键回到主菜单\n");
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else insystem();
}
}
}
public void deposit_1()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入存款金额:");
int num=0;
if(can.hasNextInt())
{
num=can.nextInt();
}
else
{
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else
{
System.out.println("输入错误,请重新输入");
deposit_1();
}
}
}
if(num>0)
{
Account ss=new Account();
me.setAccountbalance(me.getAccountbalance()+num);
me.setAmount(me.getAmount()+num);
ss=me;
map.setElementAt(ss, index);
achieve();
}
else
{
System.out.println("输入错误,请重新输入");
deposit_1();
}
}
void achieve()
{
me.setOperatetype(1);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户存款成功");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
System.out.println("\t输入q退出到账号菜单,按其他任意键回到主菜单\n");
//1
Account ss=new Account();
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else insystem();
}
}
public void insert_1() throws IOException
{
File a=new File("accountinformation.txt");
FileInputStream b = new FileInputStream(a);
map.clear();
InputStreamReader c=new InputStreamReader(b,"UTF-8");
{
BufferedReader bufr =new BufferedReader(c);
String line = null;
boolean g_tr=false;
while((line = bufr.readLine())!=null){
if(!g_tr)
{
g_tr=true;
continue;
}
Account st=new Account();
String ook[]=line.split(" "); //字符串变成字符串数组
st.set(ook[0],ook[1], Integer.parseInt(ook[2]),Integer.parseInt(ook[3]));
map.add(st);
}
bufr.close();
//System.out.println(sb.toString());
}
c.close();
b.close();
}
public void insert_2() throws IOException
{
File a=new File("accountlist.txt");
FileInputStream b = new FileInputStream(a);
InputStreamReader c=new InputStreamReader(b,"UTF-8");
{
BufferedReader bufr =new BufferedReader(c);
String line = null;
maplist.clear();
boolean g_tr=false;
String ostr="",temp_str="";
while((line = bufr.readLine())!=null){
if(!g_tr)
{
g_tr=true;
continue;
}
Account st=new Account();
String ook[]=line.split(" ");
st.setAccountID(ook[3]);
st.set_1(ook[0],Integer.parseInt(ook[1]),Integer.parseInt(ook[2]));
if(me.getAccountID().equals(ook[3]))
{
ostr=ook[0];
me.setAmount(Integer.parseInt(ook[1]));
me.setOperatedate(ook[0]);
}
maplist.add(st);
}
Date dt = new Date(); //获取时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //对时间格式化
temp_str=sdf.format(dt);
if(!ostr.equals(temp_str))
{
me.setAmount(0);
me.setOperatedate(temp_str);
}
bufr.close();
}
c.close();
b.close();
}
public void output_1() throws IOException
{
Account st=new Account();
File a=new File("accountinformation.txt");
FileOutputStream b = new FileOutputStream(a);
OutputStreamWriter c=new OutputStreamWriter(b,"UTF-8");
it=map.iterator();
while(it.hasNext())
{
c.append("\r\n");
st=it.next();
c.append(st.getAccountID()+" "+st.getAccountname()+" "+st.getAccountpassword()+" "+st.getAccountbalance());
}
c.close();
b.close();
}
public void output_2() throws IOException
{
File a=new File("accountlist.txt");
FileOutputStream b = new FileOutputStream(a,true);
String temp_str="";
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
temp_str=sdf.format(dt);
OutputStreamWriter c=new OutputStreamWriter(b,"UTF-8");
{
c.append("\r\n");
c.append(temp_str+" "+me.getAmount()+" "+me.getOperatetype()+" "+me.getAccountID());
}
c.close();
b.close();
}
//-----------------------------
public int lookp(String xuehao)
{
Account st=new Account();
int i=0;
it=map.iterator();
while(it.hasNext())
{
i++;
st=it.next();
if(st.getAccountID().equals(xuehao))
break;
}
return i;
}
public boolean isfind(String xuehao)
{
Account st=new Account();
it=map.iterator();
boolean flag=false;
while(it.hasNext())
{
st=it.next();
if(st.getAccountID().equals(xuehao))
{
me=st;
flag=true;
break;
}
}
return flag;
}
}
周四我们进行了ATM小程序考试,这个考试让我认识到了很多。首先老师给我们的两个星期我们没有利用好,这就相当于我们没有完成我们应该完成的作业。其次我感觉这次我获得了挺多,发现自己学的那些根本就是基本中的基本。在做程序的过程中我们还要用到Java语言的很多函数。恰巧这是看书看不到的,也不会注意看的。 在这次考试中我端正了自己的思想,不会再打没有准备的仗。我也在这次考试中学到了一些知识,比如声明vector,InIterator实现文件数据的导入导出,以及file 建立文件夹 ,FileInputStream,InputStreamReader,BufferedReader实现文件导入,FileOutputStream,OutputStreamWriter实现文件导出