❶ 用C語言一個ATM取款機的程序代碼(用循環語句)
/*初始密碼和賬號都為:123456 */
#include<stdio.h>
int chaxun(int a3)
{
int b;
b=a3;
printf("你的余額為:%d\n",b) ;
}
int qukuan(int a3)
{
int a,b;
printf("請輸入您要提取的現金:\n");
scanf("%d",&a);
b=a3-a;
if(b<0)
printf("對不起 ,你的余額不足\n");
else
{
printf("請收好您的%d元現金\n",a);
a3=a3-a;
}
return (a3);
}
int gaini(int a2)
{
int a,b,c=1,d,e=1;
while(e)
{
printf("請輸入你的舊密碼:\n");
scanf("%d",&d);
if(d==a2)
e=0;
else
{
e=1;
printf("你輸入的密碼錯誤,請重新輸入:\n");
}
}
while(c)
{
printf("請輸入您的六位數新密碼\n");
scanf("%d",&a2);
printf("請確認您的六位數新密碼\n");
scanf("%d",&b);
if(a2==b)
{
if(b>100000&&b<999999&&b/(b/100000)!=111111)
{
c=0;
printf("密碼修改成功\n");
}
else
{
printf("您輸入的密碼不符合要求,請從新輸入\n");
c=1;
}
}
else
{
c=1;
printf("您兩次輸入的密碼不一致,請重新輸入:\n");
}
}
return a2;
}
int quka()
{
printf("\n 夢若保保提醒您\n");
printf("請收好您的卡片,謝謝,再見\n\n");
}
int cunkuan(int a3)
{
int i,j,k;
printf("請輸入你要存的金額\n");
scanf("%d",&k);
if(k<0)
{
printf("對不起,沒有負存款\n");
}
else
{
printf("\n您好,您已經存進去了%d元\n",k);
a3=a3+k;
}
return a3;
}
main()
{
int i,j,b=1,c,k,l,m,n;
int a1=123456,a2=123456,a3=1000;
printf("歡迎使用自動櫃員機:\n\n");
while(b==1)
{
printf("請輸入您的賬號:\n");
scanf("%d",&k);
printf("請輸入您的密碼:\n");
scanf("%d",&l);
if(k==a1&&l==a2)
{
b=0;
printf("您的賬戶余額為:%d\n",a3);
}
else
{
b=1;
printf("對不起,您輸入的賬號或者密碼有誤,請重新輸入:\n");
}
}
do
{
printf("\n請選擇您要的服務項目:\n");
printf("1.查詢余額\n");
printf("2.取款\n");
printf("3.修改密碼\n");
printf("4.取卡\n");
printf("5.存款\n");
scanf("%d",&c);
switch(c)
{
case 1:
chaxun(a3);
break;
case 2:
a3=qukuan(a3);
break;
case 3:
a2=gaini(a2);
break;
case 4:
quka();
break;
case 5:
a3=cunkuan(a3);
break;
}
}while(c!=4);
}
❷ ATM機用的是什麼系統
國內ATM機用的是windows系統。
ATM的系統分為前台客戶端和後台伺服器兩部分,前台一般都是簡化之後自動運行一個ATM的固定程序,後台則由域管理伺服器和資料庫伺服器組成。而且域管理服務組器或者資料庫伺服器組都採用分布式冗餘結構,也就是其中一部分伺服器掛掉也不會影響整個網路運行。
❸ 用c語言編寫ATM的程序,實現開戶、存款、取款、查詢余額、轉賬的業務邏輯。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
void regist();
void login();
void quite();
void inputpassword(char mima[]);
void service();
struct bank
{
char name[20];
char password[7];
int account;
double money;
}kehu;
int find;
int a[10];
struct bank one;
FILE *fp;
void main()
{
int i;
int t=1;
for(i=0;i<100;i++)
{
printf("\t\t\t\t\t\t歡迎使用青軟ATM系統\n");
printf("\t\t\t\t\t\t正在進入主界面,請稍等");
int j;
for(j=1;j<t;j++)
{
printf(".");
}
t++;
if(t==10)
{
t=1;
}
printf("\n\t\t\t\t\t\t%d%%",i);
system("cls");
}
while(1)
{
printf("\t\t\t\t\t\t服務類型: \n");
printf("\t\t\t\t\t\t[a]: 用戶注冊\n");
printf("\t\t\t\t\t\t[b]: 用戶登錄\n");
printf("\t\t\t\t\t\t[c]: 退出系統\n");
printf("\t\t\t\t\t\t請選擇服務: ");
fflush(stdin);
char xz;
scanf("%c",&xz);
if(xz=='a'||xz=='A')
{
regist();
} else if (xz=='b'||xz=='B')
{
login();
} else if(xz=='c'||xz=='C')
{
quite();
} else
{
printf("輸入有誤,請重新輸入");
}
getch();
system("cls");
}
}
void inputpassword(char mima[])
{
int i=0;
char ch;
while(1)
{
ch=getch();
if(ch!='\r')
{
if(ch!='\b'){
mima[i]=ch;
i++;
printf("*");
}else{
if(i>0){
i--;
printf("\b \b");
}
}
}else{
break;
}
}
mima[i]='\0';
printf("\n");
}
void regist()
{
fp=fopen("atm.txt","ab+");
if(fp==NULL)
{
printf("\n\t\t\t文件打開失敗!");
return;
}
system("cls");
printf("\t\t\t現在執行的是注冊函數的使用\n");
printf("\t\t請輸入用戶名: ");
fflush(stdin);
gets(kehu.name);
char password1[7];
while(1)
{
while(1)
{
printf("\n\n\t\t請輸入密碼:");
fflush(stdin);
inputpassword(kehu.password);
int n=strlen(kehu.password);
if(n==6)
{
break;
}else
{
printf("\n\t\t密碼必須為6位!");
}
}
printf("\n\t\t請輸入正確密碼!: ");
fflush(stdin);
inputpassword(password1);
if(strcmp(kehu.password,password1)==0)
{
break;
}else{
printf("\n\n\t\t兩次密碼必須相同!");
}
}
rewind(fp);
struct bank k;
if(fread(&k,sizeof(struct bank),1,fp)==1)
{
fseek(fp,-sizeof(k),2);
fread(&k,sizeof(k),1,fp);
kehu.account=k.account+1;
}else{
kehu.account=20170001;
}
kehu.money=0;
fseek(fp,0,2);
fwrite(&kehu,sizeof(struct bank),1,fp);
fclose(fp);
printf("\n\n\t\t開戶成功! ");
printf("\n\t\t您的賬號為%d!",kehu.account);
printf("\n\t\t現在請您重新登錄!");
}
void searchmoney()
{
system("cls");
printf("您現在使用的是查詢余額功能: \n");
printf("\n\n\t\t您的余額是%0.2lf",one.money);
}
void savemoney()
{
system("cls");
double inmoney;
printf("請您選擇您要存款的金額 \n");
scanf("%lf",&inmoney);
int q;
int r=1;
for(q=0;q<100;q++)
{
int w;
for(w=1;w<r;w++)
{
printf(".");
}
r++;
if(r==10)
{
r=1;
}
printf("\n\t\t\t\t\t\t正在存款%d%%",q);
system("cls");
}
one.money=one.money+inmoney;
fseek(fp,-sizeof(one),1);
fwrite(&one,sizeof(one),1,fp);
printf("\n\n\t\t\t\t\t\t您已存款成功!");
}
void withdrawalmoney()
{
system("cls");
double outputsomemoney;
printf("請您選擇您要取款的金額 \n");
scanf("%lf",&outputsomemoney);
if(one.money<outputsomemoney){
printf("您的余額已不足,請您注意!");
}else {
int q;
int r=1;
for(q=0;q<100;q++)
{
int w;
for(w=1;w<r;w++)
{
printf(".");
}
r++;
if(r==10)
{
r=1;
}
printf("\n\t\t\t\t\t\t正在取款%d%%",q);
system("cls");
}
one.money=one.money-outputsomemoney;
fseek(fp,-sizeof(one),1);
fwrite(&one,sizeof(one),1,fp);
printf("\n\n\t\t\t\t\t\t您已取款成功!請點清鈔票!");
printf("\n\n\t\t\t\t\t\t您現在的余額為%lf",one.money);
}
}
void transfermoney()
{
system("cls");
int ifang;
int qian;
fflush(stdin);
printf("\n\n\n\t\t您現在使用的是轉賬功能");
printf("\n\t\t\t請輸入您要轉賬的賬戶:");
scanf("%d",&ifang);
int n=ftell(fp);
rewind(fp);
int flag=0;
struct bank temp;
while(fread(&temp,sizeof(temp),1,fp)==1)
{
if(temp.account==ifang)
{
flag=1;
break;
}
}
if(flag==1)
{
printf("請輸入轉賬金額:");
scanf("%d",&qian);
if(one.money>=qian)
{
int q;
int r=1;
for(q=0;q<100;q++)
{
int w;
for(w=1;w<r;w++)
{
printf(".");
}
r++;
if(r==10)
{
r=1;
}
printf("\n\t\t\t\t\t\t正在轉賬,請稍後!%d%%",q);
system("cls");
}
temp.money=temp.money+qian;
fseek(fp,-sizeof(temp),1);
fwrite(&temp,sizeof(temp),1,fp);
one.money=one.money-qian;
fseek(fp,n-sizeof(one),0);
fwrite(&one,sizeof(one),1,fp);
printf("\n\t\t\t\t轉賬成功!");
}else{
printf("\n\t\t\t\t您的余額已不足!");
}
}
}
void xiugai(){
system("cls");
printf("\n\n\t\t 現在進行的是修改密碼功能\n");
char oldpassword[7];
char newpassword[7];
char newpassword1[7];
int i;
for(i=0;i<3;i++){
printf("\n\t\t\t 請輸入舊密碼:\n");
inputpassword(oldpassword);
if(strcmp(oldpassword,one.password)==0){
printf("\n\t\t\t 輸入成功!\n");
break;
}else{
printf("\n\t\t\t 密碼輸入有誤,請重新輸入!\n");
}
}
if(i<3){
while(1){
printf("\n\t\t\t 請輸入您的新密碼:\n");
inputpassword(newpassword);
printf("\n\t\t\t 請輸入您的確認密碼:\n ");
inputpassword(newpassword1);
if(strcmp(newpassword,newpassword1)==0){
strcpy(one.password,newpassword);
fseek(fp,-sizeof(one),1);
fwrite(&one,sizeof(one),1,fp);
printf("\n\t\t\t 密碼修改成功!");
break;
}else{
printf("\n\t\t\t 兩次密碼輸入不一致!");
}
}
}else{
printf("\n\t\t\t 密碼輸入錯誤!");
}
}
int zhuxiaozhanghao()
{
system("cls");
int zhuxiaoxitong;
char sf;
printf("你要注銷的賬號是%d",one.account);
printf("你是否要對此賬號進行注銷?\n\n\t\t請您選擇:注銷(Y)or不注銷(N):");
fflush(stdin);
scanf("%c",&sf);
if(sf=='y'||sf=='Y')
{
printf("正在為您注銷!\n",one.account);
zhuxiaoxitong=1;
}else{
printf("不注銷系統!\n",one.account);
}
return zhuxiaoxitong;
}
void service()
{
while(1){
system("cls");
printf("\n\n\n\t\t\t\t\t\t現在是服務系統,本系統有以下服務");
printf("\n\t\t\t\t\t\t[a] 查詢余額\n");
printf("\n\t\t\t\t\t\t[b] 存款服務\n");
printf("\n\t\t\t\t\t\t[c] 轉賬服務\n");
printf("\n\t\t\t\t\t\t[d] 取款服務\n");
printf("\n\t\t\t\t\t\t[e] 修改密碼\n");
printf("\n\t\t\t\t\t\t[f] 注銷 \n");
printf("\n\t\t\t\t\t\t[g] 退出系統\n");
char e;
printf("\n\t\t\t\t\t\t您要選擇的服務是:");
fflush(stdin);
scanf("%c",&e);
switch(e)
{ case'A':
case'a': searchmoney() ;break;
case'B':
case'b': savemoney() ;break;
case'C':
case'c': transfermoney() ;break;
case'D':
case'd': withdrawalmoney() ;break;
case'E':
case'e': xiugai() ;break;
case'F':
case'f': {int zhuxiaoxitong=zhuxiaozhanghao();{if(zhuxiaoxitong==1) return;}break;}
case'G':
case'g': quite();break;
}
printf("\n\n\n\t\t\t\t按任意鍵繼續......\n");
getch();
}
}
void login()
{
fp=fopen("atm.txt","rb+");
if(fp==NULL)
{
printf("\n\n\n\t\t\t\t文件打開失敗!");
return;
}
system("cls");
printf("\n\t\t\t\t\t\t現在執行的是登錄函數的使用\n");
int zhanghao;
printf("\n\t\t\t\t\t\t請輸入賬號:");
scanf("%d",&zhanghao);
int flag=0;
while(fread(&one,sizeof(one),1,fp)==1)
{
if(zhanghao==one.account){
flag=1;
break;
}
}
char password2[7];
if(flag==1){
int h;
for(h=0;h<3;h++){
printf("\n\t\t\t\t\t\t請輸入密碼:");
fflush(stdin);
inputpassword(password2);
if(strcmp(password2,one.password)==0)
{
printf("\n\t\t\t\t\t\t登陸成功!");
service();
break;
}else{
printf("密碼不正確!");
}
}
if(h==3){
printf("\n\t\t\t您的密碼三次輸入有誤,返回");
}
}else{
printf("無此賬號!");
}
fclose(fp);
}
void quite()
{
system("cls");
printf("\t\t\t現在執行的是退出函數的使用\n");
exit(0);
}
❹ 編寫一個關於「ATM系統」c語言程序。 要求,1功能:存錢,取錢,轉賬,修改密碼,只要現實中有的都得有,
下面的是我自己寫的一個, 裡面很多細節都沒有進行細致的處理, 只是粗略的實現了基本的功能
後面有我的測試數據, 希望能有幫助
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _account
{
char * UID;
char * pwd;
int balance;
char * UName;
}ACCOUNT, * PACCOUNT;
void InitAccount(PACCOUNT pA); // 初始化賬戶
void showAccount(ACCOUNT A, bool flag); // 顯示賬戶信息, flag表示是否顯示全部信息. 如果是true則需要輸入用戶密碼
bool deposite(PACCOUNT pA); // 存錢, 內部需要密碼驗證並輸入金額
bool withDraw(PACCOUNT pA); // 取錢, 內部需要密碼驗證並輸入金額
bool transfer(PACCOUNT pA, PACCOUNT pB); // 轉賬, 需要密碼驗證, 並輸入金額
bool conct(PACCOUNT pA, int chose, PACCOUNT pB); // 處理, 就是根據菜單項處理用戶的操作選擇
void modifyPwd(PACCOUNT pA); // 更改用戶密碼
bool Authentication(PACCOUNT pA); // 密碼認證, 3次機會輸入密碼
void memFree(PACCOUNT pA, PACCOUNT pB); // 在堆上分配的內存的釋放
int main(void)
{
// 建立兩個賬戶, 分別是操作賬戶和接受轉賬的賬戶
PACCOUNT pMainAcc = (PACCOUNT)malloc(sizeof(ACCOUNT));
PACCOUNT pAssistAcc = (PACCOUNT)malloc(sizeof(ACCOUNT));
// 初始化兩個賬戶的信息
InitAccount(pMainAcc);
InitAccount(pAssistAcc);
// 進行菜單控制, 提供用戶操作
int chose = -1;
while(chose != 0)
{
printf("\n1. 存錢\t2. 取錢\t3. 轉賬\t4. 更改密碼\t5. 顯示賬戶信息\t0.退出\n");
scanf("%d", &chose);
conct(pMainAcc, chose, pAssistAcc);
}
return 0;
}
bool conct(PACCOUNT pA, int chose, PACCOUNT pB)
{
bool rtnflag = true;
switch(chose)
{
case 1:
if(!deposite(pA))
printf("操作失敗!");
else
printf("操作成功!");
break;
case 2:
if(!withDraw(pA))
printf("操作失敗!");
else
printf("操作成功!");
break;
case 3:
if(!transfer(pA, pB))
printf("操作失敗!");
else
printf("操作成功!");
break;
case 4:
modifyPwd(pA);
break;
case 5:
showAccount(*pA, true);
break;
case 0:
rtnflag = false;
memFree(pA, pB);
break;
}
return rtnflag;
}
void InitAccount(PACCOUNT pA)
{
printf("請初始化賬戶名, 密碼, 姓名, 賬戶余額.\n");
pA->UID = (char *)malloc(sizeof(char)*20);
pA->pwd = (char *)malloc(sizeof(char)*20);
pA->UName = (char *)malloc(sizeof(char)*20);
gets(pA->UID);
gets(pA->pwd);
gets(pA->UName);
scanf("%d", &pA->balance);
getchar();
return ;
}
void showAccount(ACCOUNT A, bool flag)
{
if(flag)
{
int i = 0;
getchar();
char * tmpPwd = (char *)malloc(sizeof(char)*20);
while(strcmp(tmpPwd, A.pwd))
{
printf("請輸入賬戶%s的密碼:\n", A.UID);
gets(tmpPwd);
if(++i > 3)
{
printf("對不起, 密碼輸入錯誤!只能顯示部分信息!\n");
showAccount(A, false);
free(tmpPwd);
return ;
}
}
printf("賬戶信息如下:\n賬戶名\t賬戶密碼\t賬戶余額\t姓名\n");
printf("%6s\t%8s%8d\t%8\ts\n", A.UID, A.pwd, A.balance, A.UName);
free(tmpPwd);
}
else
{
printf("賬戶信息如下:\n賬戶名\t賬戶余額\t姓名\n");
printf("%6s\t%8d\t%4s\n", A.UID, A.balance, A.UName);
}
return ;
}
bool deposite(PACCOUNT pA)
{
if(!Authentication(pA))
return false;
int val = 0;
printf("請輸入金額:\n");
scanf("%d", &val);
pA->balance += val;
return true;
}
bool withDraw(PACCOUNT pA)
{
if(!Authentication(pA))
return false;
printf("請輸入金額");
int val = 0;
scanf("%d", &val);
if(pA->balance >= val)
{
pA->balance -= val;
}
else
{
printf("對不起, 余額不足!");
return false;
}
return true;
}
bool transfer(PACCOUNT pA, PACCOUNT pB)
{
if(!Authentication(pA))
return false;
printf("請輸入金額");
int val = 0;
scanf("%d", &val);
if(pA->balance >= val)
{
pA->balance -= val;
pB->balance += val;
}
else
{
printf("對不起, 余額不足!");
return false;
}
return true;
}
void modifyPwd(PACCOUNT pA)
{
if(Authentication(pA))
{
printf("請輸入新的密碼!");
free(pA->pwd);
pA->pwd = (char *)malloc(sizeof(char)*20);
gets(pA->pwd);
}
else
{
printf("對不起, 您沒有許可權進行密碼修改!");
}
}
bool Authentication(PACCOUNT pA)
{
getchar();
int i = 0;
char * tmpPwd = (char *)malloc(sizeof(char)*20);
while(strcmp(tmpPwd, pA->pwd))
{
printf("請輸入%s的密碼, 3次機會:\n", pA->UID);
gets(tmpPwd);
if(++i == 3)
{
return false;
}
}
return true;
}
void memFree(PACCOUNT pA, PACCOUNT pB)
{
free(pA);
free(pB);
return ;
}
/*
運行環境: VC6.0
請初始化賬戶名, 密碼, 姓名, 賬戶余額.
wed
qweasd
wednesday
800
請初始化賬戶名, 密碼, 姓名, 賬戶余額.
hu
sad
huni
200
1. 存錢 2. 取錢 3. 轉賬 4. 更改密碼 5. 顯示賬戶信息 0.退出
1
請輸入wed的密碼, 3次機會:
qwe
請輸入wed的密碼, 3次機會:
qweasd
請輸入金額:
54
操作成功!
1. 存錢 2. 取錢 3. 轉賬 4. 更改密碼 5. 顯示賬戶信息 0.退出
5
請輸入賬戶wed的密碼:
qwe
請輸入賬戶wed的密碼:
qweasd
賬戶信息如下:
賬戶名 賬戶密碼 賬戶余額 姓名
wed qweasd 854 s
1. 存錢 2. 取錢 3. 轉賬 4. 更改密碼 5. 顯示賬戶信息 0.退出
4
請輸入wed的密碼, 3次機會:
123
請輸入wed的密碼, 3次機會:
qweasd
請輸入新的密碼!123qwe
1. 存錢 2. 取錢 3. 轉賬 4. 更改密碼 5. 顯示賬戶信息 0.退出
1
請輸入wed的密碼, 3次機會:
qweasd
請輸入wed的密碼, 3次機會:
123qwe
請輸入金額:
43
操作成功!
1. 存錢 2. 取錢 3. 轉賬 4. 更改密碼 5. 顯示賬戶信息 0.退出
5
請輸入賬戶wed的密碼:
123qwe
賬戶信息如下:
賬戶名 賬戶密碼 賬戶余額 姓名
wed 123qwe 897 s
1. 存錢 2. 取錢 3. 轉賬 4. 更改密碼 5. 顯示賬戶信息 0.退出
0
Press any key to continue
*/
/*
要求:使用字元用戶界面。當輸入給定的卡號和密碼(初始卡號和密碼為123456)時,系統能登錄ATM櫃員機系統,用戶可以按照以下規則進行:
1、查詢余額:初始余額為10000元
2、ATM取款:每次取款金額為100的倍數,總額不超過5000元,支取金額不允許透支。
3、ATM存款:不能出現負存款。
4、修改密碼:新密碼長度不小於6位,不允許出現6位完全相同的情況,只有舊密碼正確,新密碼符合要求,且兩次輸入相同的情況下才可以成功修改密碼。
(卡號密碼余額放到文件中)
*/
public class ATM {
private Account acc;
private File dataFile;
private FileWriter fw;
private BufferedWriter bw;
private String filePath = "./data.txt";
public ATM() {
this.acc = new Account();
try {
this.dataFile = new File(this.filePath);
if (!this.dataFile.exists()) {
this.dataFile.createNewFile();
}
this.fw = new FileWriter(this.filePath);
this.bw = new BufferedWriter(this.fw);
} catch (IOException io) {
System.err.println("Cannot open file");
io.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new ATM().interact();
}
public void interact() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Account #: ");
String temp = br.readLine();
System.out.println("Password: ");
String temp2 = br.readLine();
if (!this.acc.isValid(Long.parseLong(temp.trim()), temp2.trim()) {
System.err.println("Wrong password");
return;
}
System.out.println("1. Account Inquery.");
System.out.println("2. Withdraw");
System.out.println("3. Deposit.");
System.out.println("4. Change Password.");
System.out.println("5. Export to File.");
System.out.println("0. Exit.");
int c = 100;
while (c != 0) {
String str = br.readLine();
try {
int c = Integer.parseInt(str.trim());
} catch (NumberFormatException nfe) {
System.err.println("Invalid choice");
continue;
}
switch (c) {
case 0:
System.out.println("Thank you");
break;
case 1:
System.out.println("Balance: " + this.acc.balanceInquery());
break;
case 2:
System.out.println("How much? ");
String temp = br.readLine();
try {
long ammount = Long.parseLong(temp.trim());
this.acc.withdraw(ammount);
break;
} catch (NumberFormatException nfe) {
System.err.println("Invalid amount");
continue;
}
case 3:
System.out.println("How much? ");
String temp = br.readLine();
try {
long ammount = Long.parseLong(temp.trim());
this.acc.deposit(ammount);
break;
} catch (NumberFormatException nfe) {
System.err.println("Invalid amount");
continue;
}
case 4:
System.out.println("Old password: ");
String temp = br.readLine();
System.out.println("New password: ");
String temp2 = br.readLine();
this.acc.changePassword(temp, temp2);
break;
case 5:
this.bw.write(this.acc.toString());
break;
default:
break;
}
}
}
}
class Account {
private long accNo = 123456;
private String pass = "123456";
private long balance = 10000;
public Account() {
}
public boolean isValid(long accNo, String pass) {
return (this.accNo == accNo) && (pass.equals(this.pass));
}
public void changePassword(String oldPass, String password) {
if (!oldPass.equals(this.pass)) {
System.err.println("Wrong password.");
return;
}
if (password.length < 6) {
System.err.println("Password too short");
return;
}
if (password.equals(this.pass)) {
System.err.println("Password cannot be the same.");
return;
}
this.pass = password;
}
public long balanceInquery() {
return this.balance;
}
public void withdraw(long amount) {
if (amount > 5000 || amount < 0) {
System.err.println("Withdraw limit: $0-$5000");
return;
}
if ((amount % 100) != 0) {
System.err.println("The amount has to be a proct of 100");
return;
}
long newBalance = this.balance - amount;
if (newBalance < 0) {
System.err.println("Not enough money in the account");
return;
}
this.balance = newBalance;
}
public void deposit(long amount) {
if (amount < 0) {
System.err.println("Cannot deposit negative amount");
return;
}
this.balance += amount;
}
public String toString() {
return ("Account #: " + this.accNo + "\n" + "Password: " + this.pass + "\n" + "Balance: " + this.balance);
}
}
❻ 一個用java模擬ATM機的代碼且資料庫為mysql,
最後一列為備注 1、 管理員表(tb_admin) 欄位 類型 約束 備注 aId number(6) 主鍵 --管理員編號 aName varchar2(10) 唯一、非空 --管理員登陸名 aPassword varchar2(16) 非空 --管理員登陸密碼 aLastDate date 非空 --上次登陸時間 aNowDate date 非空 --本次登陸時間 2、 銀行卡登陸表(tb_login) 欄位 類型 約束 備注 lId number(8) 主鍵 --登錄ID lCardNumber varchar2(19) 引用銀行卡信息表 卡號 lPassword number(6) 非空 銀行卡密碼 bIsLock char(1) 默認1 是否被鎖,0表示被鎖,1表示開啟 lTime number(10) 初始為0 登陸次數 aLastDate date 非空 上次登陸時間 aNowDate date 非空 本次登陸時間 3、 客戶詳細資料表(tb_userInfo) 欄位 類型 約束 備注 usId number(8) 主鍵 客戶ID usName varchar2(10) 非空 客戶姓名 usIDNumber varchar2(18) 非空 客戶身份證號碼 usSex char(1) 默認0 客戶性別,0表示男,1表示女 usTel varchar2(11) 非空 客戶電話 usAddress varchar2(50) 非空 客戶地址 4、 銀行支行表(tb_Branch) 欄位 類型 約束 備注 bId number(3) 主鍵 支行ID bName varchar2(20) 唯一、非空 支行名 bAddress varchar2(100) 非空 支行地址 5、 銀行卡信息表(tb_CardInfo) 欄位 類型 約束 備注 bCardID number(19) 主鍵 卡號 bBalance number(8,2) 默認0.00 余額 bUserId number(8) 引用客戶詳細資料表 卡對應用戶ID bBranchID number(4) 引用支行表 支行ID bDate date 默認系統時間 開戶時間 6、 銀行卡交易類型表(tb_TransType) 欄位 類型 約束 備注 tId number(2) 主鍵 類型ID tType nvarchar2(6) 唯一 類型(轉賬、存款、取出等) 7、 銀行卡個人賬戶存、取款記錄表(tb_ Pacount) 欄位 類型 約束 備注 tId number(10) 主鍵 交易記錄流水號 tType number(2) 引用交易類型表 交易類型ID tCardID number(19) 引用銀行卡信息表 交易卡號 tamount number(10) 非空 交易金額 tDate date 非空 交易時間 8、 銀行卡轉賬等交易記錄表(tb_TransInfo) 欄位 類型 約束 備注 tId number(10) 主鍵 交易記錄流水號 tType number(2) 引用交易類型表 交易類型ID tCardIDout number(19) 引用銀行卡信息表 交易金額轉出卡號 tCardIDIn number(19) 引用銀行卡信息表 交易金額轉入卡號 tamount number(10) 非空 交易金額 tDate date 非空 交易時間
❼ 如何用Java編寫模擬ATM取款機的程序
import java.io.IOException;
/**
* ATM機類
*
* 查看余額
*
* 取款
*
* 存款
*
* 退出系統
*
*
*
*/
public class ATM {
static double yue = 1200.00;
public static void main(String[] arg) {
ATM localTest1 = new ATM();
localTest1.ATM_Operate();
}
/**
* ATM機的操作
*/
private void ATM_Operate() {
System.out.println("歡迎使用中國工商銀行ATM取款機");
System.out.println("1、查看余額 2、取款");
System.out.println("3、存款 0、退出");
System.out.print("請輸入您需要的服務:");
byte[] buffer = new byte[512];
try {
int count = System.in.read(buffer);// 返回實際讀取的位元組數
System.out.print("您輸入的是:");
for (int i = 0; i < count; i++) {
System.out.print("" + (char) buffer[i]);
}
if ((char) buffer[0] == '1') {
// 查看余額
System.out.println("您的余額是:¥" + yue + "元");
System.out.println();
ATM_Operate();
} else if ((char) buffer[0] == '2') {
// 取款
withdrawal();
System.out.println();
ATM_Operate();
} else if ((char) buffer[0] == '3') {
// 存款
deposit();
System.out.println();
ATM_Operate();
} else if ((char) buffer[0] == '0') {
// 退出
System.out.println("您已經成功退出系統,謝謝你的使用");
System.exit(0);
} else {
System.out.println("輸入不合法,請重新輸入");
System.out.println();
ATM_Operate();
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 取款
*
* @throws IOException
*/
private void withdrawal() throws IOException {
byte[] buffer = new byte[512];
System.out.print("請輸入您要取出的金額:¥");
int count2 = System.in.read(buffer);// 返回實際讀取的位元組數
System.out.print("您輸入的金額是:");
for (int i = 0; i < count2 - 1; i++) {
System.out.print("" + (char) buffer[i]);
}
System.out.println();
// 字元0 ~ 9對應ASCII值48 ~ 57
boolean flag = false;
for (int i = 0; i < count2 - 1; i++) {
if ((char) buffer[i] > 47 && (char) buffer[i] < 58) {
if (i == count2 - 2) {
flag = true;
}
} else {
// 輸入的字元不是數值
System.out.println("輸入不合法,請重新輸入");
withdrawal();
break;
}
}
System.out.println();
if (flag) {
System.out.print("您已成功取出¥:");
String num = "";
for (int i = 0; i < count2 - 1; i++) {
System.out.print("" + (char) buffer[i]);
num += (char) buffer[i];
}
yue -= Double.valueOf(num);
System.out.print(",現在余額¥:" + yue);
}
}
/**
* 存款
*
* @throws IOException
*/
private void deposit() throws IOException {
byte[] buffer = new byte[512];
System.out.print("請輸入您要存入的金額:¥");
int count2 = System.in.read(buffer);// 返回實際讀取的位元組數
System.out.print("您輸入的金額是:");
for (int i = 0; i < count2 - 1; i++) {
System.out.print("" + (char) buffer[i]);
}
System.out.println();
// 字元0 ~ 9對應ASCII值48 ~ 57
boolean flag = false;
for (int i = 0; i < count2 - 1; i++) {
if ((char) buffer[i] > 47 && (char) buffer[i] < 58) {
if (i == count2 - 2) {
flag = true;
}
} else {
// 輸入的字元不是數值
System.out.println("輸入不合法,請重新輸入");
withdrawal();
break;
}
}
System.out.println();
if (flag) {
System.out.print("您已成功存入¥:");
String num = "";
for (int i = 0; i < count2 - 1; i++) {
System.out.print("" + (char) buffer[i]);
num += (char) buffer[i];
}
yue += Double.valueOf(num);
System.out.print(",現在余額¥:" + yue);
}
}
}
❽ 遠維比程序員高一級嗎
兩者沒有等級之分。
銀行遠維是指銀行對系統進行遠程升級或更新等操作。 一般遠程維護期間ATM,網銀,手機銀行等均不能辦理業務,且銀行遠程維護一般時間為半夜,不會影響客戶正常的業務。銀行遠程維護是為了清除銀行系統運行中發生的故障和錯誤,維護人員要對系統進行必要的修改與完善;為了使銀行系統適應用戶環境的變化,滿足新提出的需要,也要對原系統遠程做些局部的更新,這些工作統稱為遠程系統維護。
程序員是從事程序開發、程序維護的專業人員。程序員一般需要會做:確認通過審查方案的目標,輸入數據,分析師,監事,和客戶的輸出要求的項目要求。通常情況下將程序員分為程序設計人員和程序編碼人員,軟體從業人員分為初級程序員、中級程序員、高級程序員(現為軟體設計師)、系統分析員,系統架構師,測試工程師六大類。