package qwe;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;
public class denglu {
static int count=0;
public static void dengluzhanghu() throws IOException
{
System.out.println("请输入登录卡号");
FileInputStream in=new FileInputStream("xinxi.txt");
Scanner s1=new Scanner(System.in);
String b1=s1.next();
char[]shuzu3=b1.toCharArray();
System.out.println("请输入登录密码");
Scanner s2=new Scanner(System.in);
String b2=s1.next();
char[]shuzu4=b2.toCharArray();
int s=in.read();
int i=0;
int[]shuzu1=new int[6];
int[]shuzu2=new int[6];
while(s!=-1&&i<6){
shuzu1[i]=s;
s=in.read();
i++;
}
i=0; //将i重新赋值为0
while(s!=-1&&i<6){
shuzu2[i]=s;
s=in.read();
i++;
}
in.close();
if(count>1) {
System.out.println("您输错了三次密码,账户被锁定了");
System.exit(0);
}
for(int j=0;j<6;j++)
{
if((shuzu1[j])==shuzu3[j])
{
if((shuzu2[j])==shuzu4[j])
{
continue;
}
else {
System.out.println("输入的密码不对请重新登陆");
count++;
dengluzhanghu();
break;
}
}
else {
System.out.println("输入的卡号不对请重新登陆");
dengluzhanghu();
break;
}
}
System.out.println("登陆成功");
denglujiemian();
}
public static void denglujiemian() throws IOException {
System.out.println("*****************");
System.out.println("****欢迎登录*****");
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退出");
Scanner a=new Scanner(System.in);
int b=a.nextInt();
switch(b)
{
case 1:
cunkuanqukuan.chakanyue();
break;
case 2:
cunkuanqukuan.cunkuan();
break;
case 3:
cunkuanqukuan.qukuan();
break;
case 4:
zhuce.gaimima();
break;
case 5:
System.out.println("退出成功");
System.exit(0);;
}
}
}
package qwe;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class zhuce {
public void zhucezhanghu() throws IOException {
System.out.println("请输入注册卡号(六位数字)");
FileWriter out=new FileWriter("xinxi.txt",true);
Scanner s1=new Scanner(System.in);
String b1=s1.next();
out.write(b1);
out.close();
System.out.println("请输入登注册密码(六位密码)");
FileWriter out1=new FileWriter("xinxi.txt",true);
Scanner s2=new Scanner(System.in);
String b2=s2.next();
out1.write(b2);
out1.close();
System.out.println("注册成功");
}
public static void gaimima() throws IOException
{
System.out.println("请输入修改密码(六位密码)");
Scanner a=new Scanner(System.in);
String s=a.next();
char shuzu1[]=s.toCharArray();
System.out.println("请再次输入修改密码(六位密码)");
Scanner a1=new Scanner(System.in);
String s1=a.next();
char shuzu2[]=s.toCharArray();
for(int i=0;i<6;i++)
{
if(shuzu1[i]!=shuzu2[i])
{
System.out.println("您输入的两次密码不一致修改错误");
System.exit(0);
}
}
FileReader in=new FileReader("xinxi.txt");
char []shuzu3=new char[18];
for(int i=0;i<18;i++)
{
shuzu3[i]=(char) in.read();
}
for(int i=0;i<6;i++)
{
shuzu3[i+6]=shuzu1[i];
}
FileWriter out1=new FileWriter("xinxi.txt");
for(int i=0;i<18;i++)
{
out1.write(shuzu3[i]);
}
out1.close();
System.out.println("修改成功");
System.out.println("请按1建返回登陆界面");
Scanner c=new Scanner(System.in);
int b=c.nextInt();
switch(b)
{
case 1:
denglu.dengluzhanghu();
break;
}
}
}
package qwe;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class cunkuanqukuan {
public static void cunkuan() throws IOException {
int count=0;
System.out.println("请输入存款金额(必须是100的整数倍的6位数)");
Scanner s1=new Scanner(System.in);
int cunqianshu=s1.nextInt();
FileReader in=new FileReader("xinxi.txt");
int []yuan=new int[18];
for(int i=0;i<18;i++)
{
yuan[i]=in.read();
}
for(int i=17;i>11;i--)
{
yuan[i]=yuan[i]-48;
int a=cunqianshu%10;
cunqianshu=cunqianshu/10;
int b=(yuan[i]+a+count)/10;
yuan[i]=(yuan[i]+a+count)%10;
count=b;
}
if(count!=0)
{
System.out.println("您的账户存不了这么多钱");
System.out.println("请按1建返回上级登录界面");
Scanner c=new Scanner(System.in);
int b=c.nextInt();
switch(b)
{
case 1: denglu.denglujiemian();;
break;
}
System.exit(0);
}
FileWriter out2=new FileWriter("xinxi.txt");
for(int i=0;i<18;i++)
{
if(i>11) {
yuan[i]=yuan[i]+48;
}
out2.write(yuan[i]);
}
out2.close();
chakanyue();
System.out.println("请按1建返回上级登录界面");
Scanner c=new Scanner(System.in);
int b=c.nextInt();
switch(b)
{
case 1:
denglu.denglujiemian();;
break;}
}
public static void chakanyue() throws IOException {
FileReader yue=new FileReader("xinxi.txt");
int []yuan=new int[18];
int s=yue.read();
for(int i=0;i<18&&s!=-1;i++)
{
yuan[i]=s;
s=yue.read();
}
System.out.println("当前的余额为:");
for(int i=12;i<18;i++)
{
System.out.print((char)yuan[i]);
}
System.out.println("元");
System.out.println("请按1建返回上级登录界面");
Scanner c=new Scanner(System.in);
int b=c.nextInt();
switch(b)
{
case 1:
denglu.denglujiemian();;
break;}
}
public static void qukuan() throws IOException {
int count=0;
System.out.println("请输入取款金额(必须是100的整数倍的6位数)");
Scanner s1=new Scanner(System.in);
int cunqianshu=s1.nextInt();
FileReader in=new FileReader("xinxi.txt");
int []yuan=new int[18];
for(int i=0;i<18;i++)
{
yuan[i]=in.read();
}
for(int i=17;i>11;i--)
{
yuan[i]=yuan[i]-48;
int a=cunqianshu%10;
int b=yuan[i]-a+count;
if(b>=0) {
yuan[i]=(yuan[i]-a+count)%10;
count=0;
}
else {yuan[i]=(10+yuan[i]-a+count)%10;
count=-1;}
cunqianshu=cunqianshu/10;
}
if(count==-1)
{
System.out.println("您的账户取不出那么多钱");
System.out.println("请按1建返回上级登录界面");
Scanner c=new Scanner(System.in);
int b=c.nextInt();
switch(b)
{
case 1:
denglu.denglujiemian();;
break;}
System.exit(0);
}
FileWriter out2=new FileWriter("xinxi.txt");
for(int i=0;i<18;i++)
{
if(i>11) {
yuan[i]=yuan[i]+48;
}
out2.write(yuan[i]);
}
out2.close();
chakanyue();
System.out.println("请按1建返回上级登录界面");
Scanner c=new Scanner(System.in);
int b=c.nextInt();
switch(b)
{
case 1:
denglu.denglujiemian();;
break;}
}
}
package qwe;
import java.io.IOException;
public class test {
public static void main(String[] args) throws IOException {
denglu dengluzhanghu1=new denglu();
dengluzhanghu1.dengluzhanghu();
}
}