ATM

weixin_30588675發表於2020-04-05

Account.java類

package ATM模擬;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.util.StringTokenizer;
import java.io.IOException;
import java.text.SimpleDateFormat;  
import java.util.Date;  
public class Account {
 String accountID;//用於儲存學生的使用者賬號(由八位數字組成)。
 String accountname;//用於儲存賬戶的名稱。
 String operatedate;//用於儲存操作的時間,由十位字元組成,顯示格式為“2018-09-20”。   
 int operatetype;//用於儲存操作賬戶的型別,具體描述為“1”表示存款,“2”表示取款,“3”表示轉
 String accountpassword;//用於使用者密碼,由六位數字組成。
 int accountbalance;//用於儲存賬戶餘額,預設為0。
 int amount;//表示操作流水金額。
 public Account() {
  accountID="20173575";
  accountname="WOSHINPC";
  operatedate="2017-9-23";
  operatetype=0;
  accountpassword="201735";
  accountbalance=0;
  amount=0;
 }
 public Account(String accountID, String accountname, String operatedate, int operatetype, String accountpassword,
   int accountbalance, int amount) {
  this.accountID = accountID;
  this.accountname = accountname;
  this.operatedate = operatedate;
  this.operatetype = operatetype;
  this.accountpassword = accountpassword;
  this.accountbalance = accountbalance;
  this.amount = amount;
 }
 
 public Account(String accountID, String accountname, String accountpassword, int accountbalance) {
  this.accountID = accountID;
  this.accountname = accountname;
  this.accountpassword = accountpassword;
  this.accountbalance = accountbalance;
 }
 
 public Account(String accountID, String accountname, String operatedate, int operatetype, int amount) {
  super();
  this.accountID = accountID;
  this.accountname = accountname;
  this.operatedate = operatedate;
  this.operatetype = operatetype;
  this.amount = amount;
 }
 public String getAccountID() {
  return accountID;
 }
 public void setAccountID(String accountID) {
  this.accountID = accountID;
 }
 public String getAccountname() {
  return accountname;
 }
 public void setAccountname(String accountname) {
  this.accountname = accountname;
 }
 public String getOperatedate() {
        long timemillis = System.currentTimeMillis();
      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
      operatedate=df.format(new Date(timemillis));  
  return operatedate;
 }
 public void setOperatedate(String operatedate) {
  this.operatedate = operatedate;
 }
 public int getOperatetype() {
  return operatetype;
 }
 public void setOperatetype(int operatetype) {
  this.operatetype = operatetype;
 }
 public String getAccountpassword() {
  return accountpassword;
 }
 public void setAccountpassword(String accountpassword) {
  this.accountpassword = accountpassword;
 }
 public int getAccountbalance() {
  return accountbalance;
 }
 public void setAccountbalance(int accountbalance) {
  this.accountbalance = accountbalance;
 }
 public int getAmount() {
  return amount;
 }
 public void setAmount(int amount) {
  this.amount = amount;
 }
 public void writeAccount(PrintWriter out){
 out.println(getAccountID()+"|"+getAccountname() +"|"+getAccountpassword()+"|"+getAccountbalance()); 
 }
 public void readAccount(BufferedReader in)throws IOException{
  String ss=in.readLine();
  StringTokenizer St=new StringTokenizer(ss,"|");
  accountID=St.nextToken();
  accountname=St.nextToken();
  accountpassword=St.nextToken();
  accountbalance=Integer.parseInt(St.nextToken());
 }
 public void write1Account(PrintWriter out){
 out.println(getAccountID()+"|"+getAccountname() +"|"+getOperatedate()+"|"+getOperatetype()+"|"+getAmount()); 
 }
 public void read1Account(BufferedReader in)throws IOException{
  String ss=in.readLine();
  StringTokenizer St=new StringTokenizer(ss,"|");
  accountID=St.nextToken();
  accountname=St.nextToken();
  operatedate=St.nextToken();
  operatetype=Integer.parseInt(St.nextToken());
  amount=Integer.parseInt(St.nextToken());
 }
}
 
 
AccountManager.java類
package ATM模擬;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.File;
import java.io.FileNotFoundException;
public class AccountManager {
 private Account[] a1 = new Account[5];
 private String Infor = "accountinformation.txt";
 private String List = "accountlist.txt";
 private String Today = "2018-9-20";
public void login()throws IOException{
 System.out.println("***************************************************************");
 System.out.println("              歡迎使用中國工商銀行自動櫃員系統");
 System.out.println("***************************************************************");
 System.out.println("                    請輸入您的賬號:");
 Scanner sc = new Scanner(System.in);
 int a= 5;
 String b = sc.next();
 while(a>3){
  for(int i=0;i<5;i++){
   if(a1[i].getAccountID().equals(b))
   {a=i;break;
   }
   
   if(a==5){
    System.out.println(" 該卡不是工行卡!");
    login();
   }
   else{
    aword(a);
   }
  }
 }
}
public void aword(int a)throws IOException{
 System.out.println("***************************************************************");
 System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
 System.out.println("***************************************************************");
 System.out.println("                    請輸入您的密碼:");
   int time= 0;
   Scanner sc = new Scanner (System.in);
           while(time<3){
                String saving = sc.nextLine();
                if(a1[a].getAccountpassword().equals(sc))
                     System.out.println("密碼錄入錯誤");
                 else
                    break;
                 time++;
             }
             if(time==3)
              login();
             else
              serviceAll(a);
        }
public void serviceAll(int a)throws IOException{
    System.out.println("***************************************************************");
        System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
        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("                      請輸入:");
        Scanner sc = new Scanner (System.in);
        int temp = sc.nextInt();
              switch(temp)
                 {
                case 1:a1[a].setOperatetype(1);writefile();deposit(a);break;
                 case 2:a1[a].setOperatetype(2);writefile();draw(a);break;
                 case 3:a1[a].setOperatetype(3);writefile();zhuan(a);break;
                 case 4:a1[a].setOperatetype(4);writefile();xiugai(a);break;
                 case 5:a1[a].setOperatetype(5);writefile();yu(a);break;
                 default:serviceAll(a);break;
                 }   
}
public void deposit(int a)throws IOException{
    System.out.println("***************************************************************");
    System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
    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("                 請輸入存款金額;");
    Scanner sc = new Scanner (System.in);
    if(sc.hasNext("q"))
     login();
    else{
     int JinE = sc.nextInt();//記錄金額
                  if(JinE<=0)
                  {
                      System.out.println(" 輸入金額有誤");
                      deposit(a);
                  }
                  else
                  {
                      a1[a].setAmount(a1[a].getAmount()+JinE);
                      a1[a].setAccountbalance(a1[a].getAccountbalance()+JinE);
                      //-----------------------[資料載入文件]
                      System.out.println("***************************************************************");
                      System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                      System.out.println("****************************************************************");
                      System.out.println("                當前賬戶存款操作成功。");
                      System.out.println("             當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID());
                      pw.print(" ");
                      pw.print(Today);
                      a1[a].setOperatedate(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();
                     //----------------------------------------
                      serviceAll(a);
                  }
              }       
     
     
    }
public void draw(int a)throws IOException{
  System.out.println("***************************************************************");
  System.out.println("歡迎"+a1[a].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("***************************************************************:");
  Scanner sc = new Scanner (System.in);
  int q = sc.nextInt();
  switch(q){
           case 1:
           {
               if(a1[a].getAccountbalance()<100)
               {
                   System.out.println("賬戶餘額不足");
                   deposit(a);
               }
               else
               {
                   a1[a].setAmount(a1[a].getAmount()+100);
                   a1[a].setAccountbalance(a1[a].getAccountbalance()-100);
                   System.out.println("***************************************************************");
                   System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                   System.out.println("****************************************************************");
                   System.out.println("             當前賬戶取款操作100元成功。");
                   System.out.println("             當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID());
                   pw.print(" ");
                   pw.print(Today);
                   a1[a].setOperatedate(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();
                  serviceAll(a);
               }
               break;
          }
           case 2:
           {
               if(a1[a].getAccountbalance()<500)
               {
                   System.out.println("賬戶餘額不足");
                   deposit(a);
              }
               else
               {
                   a1[a].setAmount(a1[a].getAmount()+500);
                   a1[a].setAccountbalance(a1[a].getAccountbalance()-500);
                   System.out.println("***************************************************************");
                   System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                   System.out.println("****************************************************************");
                   System.out.println("             當前賬戶取款操作500元成功。");
                   System.out.println("             當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID());
                   pw.print(" ");
                   pw.print(Today);
                   a1[a].setOperatedate(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();
                   //-----------------------------------
                   serviceAll(a);
               }
               break;
           }
           case 3:
           {
               if(a1[a].getAccountbalance()<1000)
               {
                   System.out.println("賬戶餘額不足");
                   draw(a);
              }
               else
               {
                   a1[a].setAmount(a1[a].getAmount()+1000);
                   a1[a].setAccountbalance(a1[a].getAccountbalance()-1000);
                   System.out.println("***************************************************************");
                   System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                   System.out.println("****************************************************************");
                   System.out.println("             當前賬戶取款操作1000元成功。");
                   System.out.println("             當前賬戶餘額為:"+a1[a].getAccountbalance()+"元");
                   Scanner scs = new Scanner (new FileReader(List));
                   PrintWriter pws = new PrintWriter (new FileWriter("files/LinShi"));
                   while(!scs.hasNext("ENDOFTHISFILE"))
                   {
                       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(a1[a].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();
                   //-----------------------------------
                   serviceAll(a);
               }
               break;
           }
           case 4:
           {
               if(a1[a].getAccountbalance()<1500)
               {
                   System.out.println("賬戶餘額不足");
                   draw(a);
               }
               else
               {
                   a1[a].setAmount(a1[a].getAmount()+1500);
                   a1[a].setAccountbalance(a1[a].getAccountbalance()-1500);
                   System.out.println("***************************************************************");
                   System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                  System.out.println("****************************************************************");
                   System.out.println("             當前賬戶取款操作1500元成功。");
                   System.out.println("             當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID());
                   pw.print(" ");
                   pw.print(Today);
                   a1[a].setOperatedate(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();
                   //-----------------------------------
                   serviceAll(a);
               }
               break;
           }
           case 5:
           {
               if(a1[a].getAccountbalance()<2000)
               {
                   System.out.println("賬戶餘額不足");
                   draw(a);
               }
               else
               {
                   a1[a].setAmount(a1[a].getAmount()+2000);
                   a1[a].setAccountbalance(a1[a].getAccountbalance()-2000);
                   System.out.println("***************************************************************");
                   System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                   System.out.println("****************************************************************");
                   System.out.println("             當前賬戶取款操作2000元成功。");
                   System.out.println("             當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID());
                   pw.print(" ");
                   pw.print(Today);
                   a1[a].setOperatedate(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();
                   //-----------------------------------
                   serviceAll(a);
               }
               break;
           }
           case 6:
           {
               if(a1[a].getAccountbalance()<5000)
               {
                   System.out.println("賬戶餘額不足");
                   draw(a);
               }
               else
               {
                   a1[a].setAmount(a1[a].getAmount()+5000);
                   a1[a].setAccountbalance(a1[a].getAccountbalance()-5000);
                   System.out.println("***************************************************************");
                   System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                   System.out.println("****************************************************************");
                   System.out.println("             當前賬戶取款操作5000元成功。");
                   System.out.println("             當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID());
                   pw.print(" ");
                   pw.print(Today);
                   a1[a].setOperatedate(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();
                   //-----------------------------------
                   serviceAll(a);
               }
               break;
           }
           case 7:
           {
               System.out.println("***************************************************************");
               System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
               System.out.println("****************************************************************");
               System.out.println("                請輸入取款金額:");
               int num = sc.nextInt();
             if(a1[a].getAccountbalance()<num)
               {
                   System.out.println("賬戶餘額不足");
                   draw(a);
               }
              else
               {
                   a1[a].setAmount(a1[a].getAmount()+num);
                   a1[a].setAccountbalance(a1[a].getAccountbalance()-num);
                   System.out.println("***************************************************************");
                   System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                   System.out.println("****************************************************************");
                   System.out.println("             當前賬戶取款操作"+num+"元成功。");
                   System.out.println("             當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID());
                   pw.print(" ");
                   pw.print(Today);
                   a1[a].setOperatedate(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();
                   serviceAll(a);
               }
               break;
           }
           case 8:
           {
               login();
               break;
           }
           case 9:
           {
              serviceAll(a);
               break;
           }
           default:draw(a);break;
           }
       }
public void zhuan(int a)throws IOException{
  System.out.println("***************************************************************");
           System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
           System.out.println("***************************************************************");
           System.out.println("                     請輸入轉賬賬戶;");
           Scanner sc = new Scanner (System.in);
           if(sc.hasNext("q"))
               login();
           String temp = sc.next();
           int tube = 5;//記錄賬戶
           for(int i=0;i<5;i++){
               if(a1[i].getAccountID().compareTo(temp)==0)
               {
                   tube = i;
                   break;
               }
           }
           if(tube==5)
           {
               System.out.println(" #:該使用者不存在");
               zhuan(a);
           }
           else
           {
               zhuan_half(a,tube);
           }
       }
public void zhuan_half(int a,int a_to)throws IOException {
           System.out.println("***************************************************************");
           System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
           System.out.println("***************************************************************");
           System.out.println("                   請輸入轉賬金額;");
           Scanner sc = new Scanner (System.in);
           if(sc.hasNext("q"))
               login();
           int JinE= sc.nextInt();
           if(JinE>a1[a].getAccountbalance())
           {
               System.out.println("賬戶餘額不足");
               zhuan_half(a,a_to);
           }
           else if(JinE<=0)
               zhuan_half(a,a_to);
           else
           {
               StringBuffer sxw = new StringBuffer(a1[a_to].getAccountname());
               sxw.deleteCharAt(0);
               System.out.println("***************************************************************");
               System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
               System.out.println("***************************************************************");
               System.out.println("          請確認是否向*"+sxw+"轉賬"+JinE+"元。");
               String makesure = sc.next();
               if(sc.hasNext("q"))
                   login();
               if(makesure.compareTo("Y")==0)
               {
                   a1[a].setAccountbalance(a1[a].getAccountbalance()-JinE);
                   a1[a].setAmount(a1[a].getAmount()+JinE);
                   a1[a_to].setAccountbalance(a1[a_to].getAccountbalance()+JinE);
                   a1[a_to].setAmount(a1[a_to].getAmount()+JinE);
                   System.out.println("***************************************************************");
                   System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
                   System.out.println("***************************************************************");
                   System.out.println("          當前賬戶向*"+sxw+"轉賬"+JinE+"元。");
                   System.out.println("          當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID());
               pw.print(" ");
               pw.print(Today);
               a1[a].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();
               //-----------------------------------
               serviceAll(a);
           }
}
public void xiugai(int a)throws IOException{
    System.out.println("***************************************************************");
         System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
         System.out.println("***************************************************************");
         String str1,str2;
         System.out.println("                  請輸入當前密碼:  ");
         Scanner sc = new Scanner (System.in);
         str1 = sc.next();
         if(sc.hasNext("q"))
             login();
         if(a1[a].getAccountpassword().compareTo(str1)==0)
         {
             System.out.println("                  請輸入修改密碼:");
             str1 = sc.next();
             if(sc.hasNext("q"))
                 login();
             System.out.println("                  請輸入確認密碼:");
             str2 = sc.next();
             if(sc.hasNext("q"))
                 login();
             if(str1.compareTo(str2)==0)
             {
                 a1[a].setAccountpassword(str1);
                 writefile();
                 System.out.println("***************************************************************");
                 System.out.println("   歡迎"+a1[a].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(a1[a].getAccountID());
                 pw.print(" ");
                 pw.print(Today);
                 a1[a].setOperatedate(Today);
                 pw.print(" ");
                 writefile();
                 pw.print("Changeaword");
                 pw.print(" ");
                 pw.println("**********");
                 while(!scp.hasNext("ENDOFTHISFILE"))
                 {
                     pw.println(scp.nextLine());
                 }
                 pw.println(scp.nextLine());
                 pw.close();
                 //-----------------------------------
                 serviceAll(a);
             }
             else
             {
                 System.out.println("          修改密碼與確認密碼不一致");
                 xiugai(a);
             }
         }
         else
         {
             System.out.println("         當前密碼錄入錯誤");
             xiugai(a);
         }
 
 
 
}  
public void yu(int a)throws IOException{
   System.out.println("***************************************************************");
            System.out.println("   歡迎"+a1[a].getAccountname()+"使用中國工商銀行自助櫃員系統");
            System.out.println("***************************************************************");
            System.out.println("                  當前賬戶餘額為:"+a1[a].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(a1[a].getAccountID().compareTo(str3)==0)
                {
                    System.out.println(sx+"、"+str1+"  "+str2+"   "+dateofthis);
                    sx++;
                }
            }
            serviceAll(a);
 

public AccountManager() throws FileNotFoundException{
         for(int i=0;i<5;i++)
             a1[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(a1[i].getAccountID());
             fl.print(' ');
             fl.print(a1[i].getAccountname());
             fl.print(' ');
             fl.print(a1[i].getOperatedate());
             fl.print(' ');
             fl.print(a1[i].getOperatetype());
             fl.print(' ');
             fl.print(a1[i].getAccountpassword());
             fl.print(' ');
             fl.print(a1[i].getAccountbalance());
             fl.print(' ');
             fl.print(a1[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++)
             a1[i]=new Account(fl.next(),fl.next(),fl.next(),fl.nextInt(),fl.next(),fl.nextInt(),fl.nextInt());
     }

}
   
主函式
package ATM模擬;
import java.io.IOException;
public class ATM {
public static void main(String[] args)throws IOException{
    AccountManager accou = new AccountManager();
         accou.login(); 
 }
}
 

轉載於:https://www.cnblogs.com/NCLONG/p/9696318.html

相關文章