import java.io.*;
import java.util.*;
public class atm
{
static int MAX = 10;
static int MAXR = 100;
static String[][] login = new String[MAX+1][2];
static int total = 100000;
public static void main(String[] args)
{
try
{
int p = 0;
BufferedReader in = new BufferedReader(new FileReader("UserInfo.txt"));
String s = in.readLine();
while(s != null)
{
StringTokenizer t = new StringTokenizer(s,"#");
login[p][0] = t.nextToken();
login[p][1] = t.nextToken();
p ++ ;
s = in.readLine();
}
}
catch(IOException e)
{
e.printStackTrace();
}
try
{
BufferedReader in = new BufferedReader(new FileReader("Record.txt"));
String s = in.readLine();
while(s != null)
{
StringTokenizer t = new StringTokenizer(s,"#");
t.nextToken();
total = total + Integer.parseInt(t.nextToken());
s = in.readLine();
}
}
catch(IOException e)
{
e.printStackTrace();
}
admHandling aH;
hqHandling hH;
String ikey, inum;
int i;
while(true)
{
i=0;
System.out.printf("请输入卡号:");
Scanner scanner = new Scanner(System.in);
inum = scanner.next();
System.out.printf("请输入密码:");
ikey = scanner.next();
for(i=0;i<MAX+1;i++)
{
if(login[i][0] != null)
{
if(login[i][0].equals(inum) && login[i][1].equals(ikey))
if(i == 0)
{
System.out.println("欢迎您!管理员");
aH = new admHandling();
aH.data();
break;
}
else
{
/*try
{
Runtime.getRuntime().exec("cmd /c start cls ");
}
catch(IOException e)
{
e.printStackTrace();
}*/
System.out.println("欢迎您!用户" + inum);
hH = new hqHandling();
hH.data(inum);
break;
}
}
}
if(i == MAX+1)
System.out.println("卡号或密码错误!");
}
}
static class person
{
String num,key,date;
int left;
protected void write(int flag)
{
try
{
RandomAccessFile fos = new RandomAccessFile("UserInfo.txt","rw");
if(flag == 0)
{
fos.seek(0);
fos.writeBytes(num + "#" + key + "#" + left + "#" + "ADMIN" + "#" + date + "\n");
}
else
{
fos.seek(fos.length());
fos.writeBytes(num + "#" + key + "#" + left + "#" + "HQ" + "#" + date + "\n");
}
fos.close();
}
catch(IOException e)
{
e.printStackTrace();
}
};
protected void changekey()
{
Scanner scanner = new Scanner(System.in);
System.out.println("请确认旧密码:");
String ikey = scanner.next();
if(!ikey.equals(key))
System.out.println("密码错误!");
else
{
String key1, key2;
System.out.printf("请输入新密码:");
String str = scanner.next();
while(str.length() < 6)
{
System.out.printf("密码长度不够,请重新输入:");
str = scanner.next();
}
key1 = str;
System.out.printf("请再次输入新密码:");
str = scanner.next();
key2 = str;
if(key1.equals(key2))
{
char t = key1.charAt(0);
int flag = 0;
for(int i=1; i < key1.length(); i++)
if(key1.charAt(i) == t)
flag ++;
if(flag == key1.length()-1)
System.out.println("密码不能为同一个数字!");
else
{
key = key2;
for(int i=0; i<MAX+1; i++)
if(this.num.equals(login[i][0]))
login[i][1] = key2;
System.out.println("密码修改成功!");
}
}
else
System.out.println("两次输入的密码不相同!");
}
}
}
static class admin extends person
{
//public admin(){}
public admin()
{
this.num = "111111";
this.key = "123456";
this.left = 0;
this.date = (new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(new Date());
this.write(0);
}
}
static class hq extends person
{
public hq(){}
public hq(String num, String key)
{
this.num = num;
this.key = key;
this.left = 10000;
this.date = (new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(new Date());
this.write(1);
}
}
static class admHandling
{
admin ad;
public admHandling()
{
ad = new admin();
try
{
BufferedReader in = new BufferedReader(new FileReader("UserInfo.txt"));
String s = in.readLine();
StringTokenizer t = new StringTokenizer(s,"#");
ad.num = t.nextToken();
ad.key = t.nextToken();
t.nextToken();
t.nextToken();
ad.date = t.nextToken();
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void end()
{
try
{
RandomAccessFile fos = new RandomAccessFile("UserInfo.txt","rw");
fos.seek(0);
fos.writeBytes(ad.num + "#" + ad.key + "#" + ad.left + "#" + "ADMIN" + "#" + ad.date + "\n");
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void data()
{
String c,s;
c = new String();
s = new String();
int flag = 0;
do
{
System.out.println("**************************");
System.out.println("1.查询所有活期用户信息");
System.out.println("2.创建活期帐号(开新卡)");
System.out.println("3.查询当前ATM资金余额");
System.out.println("4.修改密码");
System.out.println("0.退出");
System.out.println("**************************");
Scanner scanner = new Scanner(System.in);
c = scanner.nextLine();
switch(c.charAt(0))
{
case '1':
flag = 0;
try
{
BufferedReader in = new BufferedReader(new FileReader("UserInfo.txt"));
s = in.readLine();
s = in.readLine();
while(s != null)
{
flag = 1;
System.out.println(s);
s = in.readLine();
}
}
catch(IOException e)
{
e.printStackTrace();
}
if(flag == 0)
System.out.println("没有用户信息!");
break;
case '2':
System.out.printf("请输入新卡号:");
s = scanner.next();
int t;
for(t=0; t<MAX+1; t++)
if(login[t][0] != null)
if(login[t][0].equals(s))
{
System.out.println("卡号已存在!");
break;
}
if(t == MAX + 1)
{
String key1, key2;
System.out.printf("请输入新密码:");
String st = scanner.next();
while(st.length() < 6)
{
System.out.printf("密码长度不够,请重新输入:");
st = scanner.next();
}
key1 = new String(st);
char q = key1.charAt(0);
flag = 0;
for(int i=1; i < key1.length(); i++)
if(key1.charAt(i) == q)
{
flag ++;
break;
}
if(flag == key1.length()-1)
System.out.println("密码不能为同一个数字!创建失败!");
else
{
System.out.printf("请再次输入新密码:");
st = scanner.next();
key2 = new String(st);
if(key1.equals(key2))
{
for(int i=0; i<MAX+1; i++)
if(login[i][0] == null)
{
login[i][0] = s;
login[i][1] = key2;
new hq(s, key2);
break;
}
System.out.println("新用户创建成功!");
}
else
System.out.println("两次输入的密码不相同!");
}
}
break;
case '3':
System.out.println("当前ATM机余额为:" + total + "元。");
break;
case '4':
ad.changekey();
break;
case '0':
break;
default :
System.out.println("该选项不存在!");
break;
}
}while(c.charAt(0) != '0');
end();
}
}
static class hqHandling
{
hq[] huoqi = new hq[MAX];
hq temp;
int i = 0;
public hqHandling()
{
try
{
BufferedReader in = new BufferedReader(new FileReader("UserInfo.txt"));
String s = in.read