1. 程式人生 > >簡單ATM機功能實現

簡單ATM機功能實現

-a 中國 tokenizer 賬號 ace get space pass ima

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer; public class Account {
static int M=0,N=0; private String accountID;//存儲賬號
private String accountname;//賬戶名稱
private String operatedate;//2018-09-20
private int operatetype;//操作賬戶類型(1,存款2,取款3,轉賬匯款4,修改賬戶密碼5,查詢余額
private String accountpassword;//用戶密碼
private int accountbalance;//存儲賬戶余額 0
private int amount;//流水金額
void setaccountID(String t)
{
accountID=t;
}
void setaccountname(String t)
{
accountname=t;
}
void setoperatedate(String t)
{
operatedate=t;
}
void setoperatetype(int t)
{
operatetype=t;
}
void setaccountpassword(String t)
{
accountpassword=t;
}
void setaccountbalance(int t)
{
accountbalance=t;
}
void amount(int t)
{
amount=t;
}
String getaccountID()
{
return accountID;
}
String getaccountname()
{
return accountname;
}
String getoperatedate()
{
return operatedate;
}
int getoperatetype()
{
return operatetype;
}
String getaccountpassword()
{
return accountpassword;
}
int getaccountbalance()
{
return accountbalance;
}
int getamount()
{
return amount;
}
Account(String AaccountID,String Aaccountname,String Aoperatedate,int Aoperatetype,String Aaccountpassword,int Aaccountbalance,int Aamount)
{
accountID=AaccountID;
accountname=Aaccountname;
operatedate=Aoperatedate;
operatetype=Aoperatetype;
accountpassword=Aaccountpassword;
accountbalance=Aaccountbalance;
amount=Aamount;
}

public static void main(String[]args)
{
Account[] a1=null;
a1=new Account[6];
a1[0]=new Account("20173599","zhoubo","2018-09-20",1,"753951",0,0);
a1[1]=new Account("20173598","zhoubo","2018-09-20",1,"753951",0,0);
a1[2]=new Account("20173597","zhoubo","2018-09-20",1,"753951",0,0);
a1[3]=new Account("20173596","zhoubo","2018-09-20",1,"753951",0,0);
a1[4]=new Account("20173595","zhoubo","2018-09-20",1,"753951",0,0);
File file = null;
FileWriter fw = null;
file = new File("E:\\eclipse-workspace\\信 1705-1班 20173599 周博\\accountinformation.txt");
try {
if (!file.exists()) {
file.createNewFile();
}
fw=new FileWriter(file);
for(int i=0;i<5;i++)
{
fw.write(a1[i].accountID+a1[i].accountname+a1[i].accountpassword+a1[i].accountbalance);
fw.flush();
}
System.out.println("寫數據成功!");
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if(fw!=null)
{
try {
fw.close();
}catch (IOException e)
{
e.printStackTrace();
}
}
}
File file1 = null;
FileWriter fw1 = null;
file1 = new File("E:\\eclipse-workspace\\信 1705-1班 20173599 周博\\accountinformation.txt");
try {
if (!file1.exists()) {
file1.createNewFile();
}
fw1=new FileWriter(file1);
for(int i=0;i<5;i++)
{
fw1.write(a1[i].accountID+a1[i].accountname+a1[i].accountpassword+a1[i].accountbalance);
fw1.flush();
}
System.out.println("寫數據成功!");
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if(fw1!=null)
{
try {
fw1.close();
}catch (IOException e)
{
e.printStackTrace();
}
}
}
Shuru_zhanghao(a1);
Shuru_mima(a1);
M=2;
if(M==-2)
{
System.out.println("您有三次機會 如果全錯將被沒收");
for(int i=1;i<=3;i++)
{
Scanner scan=new Scanner(System.in);
String l;
l=scan.next();
if(l!=a1[N].accountpassword)
{
System.out.println("您錯了"+i+"次");
if(i==3) {
System.out.println("該賬號三次錄入密碼錯誤,該卡已被系統沒收,請與工行及時聯系處理");
break;}
}
else break;
}
}
if(M==2)
{ char ch=‘y‘;
while(ch==‘y‘)
{ System.out.println("***************************************************************");
System.out.println("\t歡迎"+a1[N].accountname+"使用中國工商銀行自助櫃員系統 ");
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("\t6、 退出:");
Scanner scan=new Scanner(System.in);/*輸入 等待輸入*/
int sc5=scan.nextInt();//輸入的值
switch(sc5)
{
case 1:
{
Cunkuan(a1);
break;
}
case 2:
{
Cunkuan(a1);
break;
}
case 5:
{
Cha_yu(a1);
}
case 6:
{
break;
}
}
}

}
}
static void Cha_yu(Account [] a)
{
System.out.println("\t當前余額為:");
System.out.println(a[N].accountbalance);
}
static void Qukuan(Account [] a)
{
System.out.println("******************************************************");
System.out.println("\t歡迎zhoubo使用中國銀行自助櫃員系統");
System.out.println("******************************************************");
System.out.println("\t請輸入取款金額:");
Scanner in=new Scanner(System.in);
int O;
O=in.nextInt();
a[N].amount=O;
a[N].accountbalance=a[N].accountbalance-a[N].amount;
System.out.println("\t當前賬戶存款操作成功");
System.out.println("\t當前余額為:");
System.out.println(a[N].accountbalance);
}
static void Cunkuan(Account [] a)
{
System.out.println("******************************************************");
System.out.println("\t歡迎"+a[N].accountname+"o使用中國銀行自助櫃員系統");
System.out.println("******************************************************");
System.out.println("\t請輸入存款金額:");
Scanner in=new Scanner(System.in);
int O;
O=in.nextInt();
a[N].amount=O;
System.out.println("******************************************************");
System.out.println("\t當前賬戶存款操作成功");
System.out.println("\t當前余額為:");
a[N].accountbalance+=a[N].amount;
System.out.println(a[N].accountbalance);
}
static void Shuru_zhanghao(Account [] a)
{
System.out.println("******************************************************");
System.out.println("\t歡迎"+a[N].accountname+"使用中國工商銀行自動櫃員系統");
System.out.println("******************************************************");
System.out.println("\t請輸入您的賬號:");
Scanner in=new Scanner(System.in);
String O;
O=in.next();
System.out.println("******************************************************");
for(int i=0;i<5;i++)
{
if(O==a[i].accountID)
{
M=1;N=i;
}
else {System.out.println("輸入正確!");M=-1;}
}
}
static void Shuru_mima(Account [] a)
{
System.out.println("******************************************************");
System.out.println("\t歡迎"+a[N].accountname+"使用中國銀行自助櫃員系統");
System.out.println("******************************************************");
System.out.println("\t請輸入您的密碼:");
Scanner in=new Scanner(System.in);
String O;
O=in.next();
System.out.println("******************************************************");
if(O==a[N].accountpassword)
{
M=2;
}
else {System.out.println("輸入正確!");M=-2;}
}
}

簡單ATM機功能實現