導航:首頁 > 編程語言 > JAVA程序ATM櫃員機模擬程序

JAVA程序ATM櫃員機模擬程序

發布時間:2022-06-10 00:24:42

① 求一個模擬ATM程序,用java編寫,完整點最好

import java.util.Scanner;

class Cust
{
String name;
int ID;
int money;
int PWD;

Scanner scan=new Scanner(System.in);

Cust()
{
name="";ID=0;money=0;PWD=0;
}
Cust(String n,int i,int m,int p)
{
name=n;ID=i;money=m;PWD=p;
}

void getMoney()
{
System.out.println("請入你要取出的金額:");
int m=scan.nextInt();
if(money>=m)
{
money=money-m;
System.out.println("已取出 $"+m);
}
else
System.out.println("余額不足");
}
void saveMoney()
{
System.out.println("請入你要存入的金額:");
int m=scan.nextInt();
money=money+m;
System.out.println("已存入 $"+m);
}
void search()
{
System.out.println("****************");
System.out.println("您的name:"+name);
System.out.println("您的ID:"+ID);
System.out.println("您的余額 $"+money);
System.out.println("****************");
}
void changePWD()
{
System.out.println("請入新密碼:");
int p=scan.nextInt();
PWD=p;
System.out.println("密碼已更改");
}

void run()
{

int sum=3;
while(sum>0)
{
System.out.println("輸入你的密碼:");
int p=new Scanner(System.in).nextInt();
if(PWD==p)
{
System.out.println("登錄成功");

System.out.println("你的帳戶");
search();

int choose=1;
while(choose>0&&choose<5)
{
System.out.println();
System.out.println("查詢\t1");
System.out.println("取錢\t2");
System.out.println("存錢\t3");
System.out.println("改密碼\t4");
System.out.println("退出\tOther");
switch(scan.nextInt())
{
case 1: search();break;
case 2: getMoney();break;
case 3: saveMoney();break;
case 4: changePWD();break;
default: return;
}
}

// x.run();
sum=0;
}
else
{
System.out.println("密碼不正確");
sum--;
if(sum>0)
System.out.println("你還有"+sum+"次機會");
else
System.out.println("您的卡已被鎖定");
}
}

}

}

class TestCust
{
public static void main(String[] args)
{
Cust[] cus=new Cust[4];

for(int j=0;j<4;j++)
{
System.out.println("\n 第"+(j+1)+"個客戶\n");
cus[j]=init();
}
System.out.println();
/* cus[0]=new Cust("FQ",1,1000,1);
cus[1]=new Cust("f",2,2000,2);
cus[2]=new Cust("q",3,3000,3);
cus[3]=new Cust("s",4,4000,4);
*/ while(true)
{
System.out.println("輸入你的帳號:");
int n=new Scanner(System.in).nextInt();
if(n<0)
System.exit(0);
int i;
for(i=0;i<cus.length;i++)
{
if(cus[i].ID==n)
{
cus[i].run();
break;
}
}
if(i==cus.length)
System.out.println("沒有此帳號");
System.out.println();
}
}

static Cust init()
{
Scanner scan=new Scanner(System.in);
System.out.print("輸入姓名:");
String name=scan.next();
System.out.print("輸入 ID :");
int ID=scan.nextInt();
System.out.print("輸入余額:");
int money=scan.nextInt();
System.out.print("輸入密碼:");
int PWD=scan.nextInt();
return new Cust(name,ID,money,PWD);
// Cust x=new Cust(name,ID,money,PWD);
// return x;
}

}

② JAVA 模擬ATM櫃員機模擬程序

/**
要求:使用字元用戶界面。當輸入給定的卡號和密碼(初始卡號和密碼為123456)時,系統能登錄ATM櫃員機系統,用戶可以按照以下規則進行:
1、查詢余額:初始余額為10000元
2、ATM取款:每次取款金額為100的倍數,總額不超過5000元,支取金額不允許透支。
3、ATM存款:不能出現負存款。
4、修改密碼:新密碼長度不小於6位,不允許出現6位完全相同的情況,只有舊密碼正確,新密碼符合要求,且兩次輸入相同的情況下才可以成功修改密碼。
(卡號密碼余額放到文件中)
*/
publicclassTest{
privatestaticintaccount;
privatestaticintpassword;
privatestaticintmoney;
privatestaticbooleanisLogin;
static{
account=123456;
password=123456;
money=10000;
isLogin=false;
}
//存款
publicvoidcun(intcunKuan){
if(cunKuan>=0){
this.money+=cunKuan;
}else{
System.out.println("存款不能為負!");
}
}
//取款
publicvoidqu(intquKuan){
if(this.money-quKuan<0){
System.out.println("余額不足!");
return;
}

if(isValid(quKuan)){
this.money-=quKuan;
}else{
System.out.println("取款不能為負,且應為100的倍數!");
}
}
//判斷是否為有效的金額
privatebooleanisValid(intmoney){
if(money>=0&&money%100==0){
returntrue;
}
returnfalse;
}

//登陸
publicvoidlogin(){
System.out.println("請輸入賬號和密碼【格式為:賬號/密碼】");
Stringlogin=newScanner(System.in).next();
if(login.equalsIgnoreCase("123456/123456")){
this.isLogin=true;
}else{
System.out.println("賬號或者密碼錯誤,請重新輸入!");
login();
}
}

//主菜單
publicvoidshow(){
System.out.println("[1]存款");
System.out.println("[2]取款");
System.out.println("[3]退出");
System.out.println("請輸入:");
intkey=newScanner(System.in).nextInt();
switch(key){
case1:
cun(newScanner(System.in).nextInt());
break;
case2:
qu(newScanner(System.in).nextInt());
break;
case3:
System.exit(0);
default:
break;
}
}
publicstaticvoidmain(String[]args){
Testt=newTest();
t.login();
if(t.isLogin){
for(;;){
t.show();
System.out.println("您當前的余額為:"+t.money);
}
}

}
}

③ 就是用JAVA編寫一個ATM的程序

你是做實習還是做真實項目,如果是真實項目,估計夠嗆,因為ATM這些要用嵌入式開發,Java需要環境,而且效率低,如果僅僅是做練習,你可以用JFrame來實現 或者swing,其實說白這些不過是一些框架類庫,你安裝了這些框架類庫,然後用一個類去繼承窗體類,其他的和一些窗體軟體開發是一樣的,用的是事件機制,說白了就是觀察者設計模式。

④ 用java編譯ATM櫃員機模擬程序

#include<iostream.h>

class consumer;

class ATM
// ATM取款機
{
public:
ATM(consumer& cn):cnsm(cn)
{
}
void welcome();
// 登陸界面
bool check_passwd(char n[],char pwd[]);
// 核對密碼
void change_passwd();
// 修改密碼
void fetchmoney();
// 取款
void information();
// 查詢信息
void exitATM();
// 退出系統
void functionshow();
// 功能界面
void lock();
// 鎖機
private:
int times;
// 記錄密碼輸入次數
consumer& cnsm;

};

class consumer
// 用戶
{
public:
friend class ATM;
consumer(char Name[],char Num[],
float Money,char Password[]);
protected:
char* get_name();
// 取得姓名
char* get_num();
// 取得卡號
char* get_passwd();
// 取得密碼
float get_money();
// 取得余額
void set_passwd(char pwd[]);
// 設置密碼
void set_money(float m);
// 取錢
private:
char passwd[8];
// 用戶密碼
char name[20];
// 用戶姓名
char num[20];
float money;
};#include"function.h"
#include<string.h>

consumer::consumer(char Name[],
char Num[],float Money,char Password[])
{
strcpy(name,Name);
strcpy(num,Num);
money=Money;
strcpy(passwd,Password);
}

float consumer::get_money()
{
return money;
}

char* consumer::get_name()
{
return name;
}

char* consumer::get_num()
{
return num;
}

char* consumer::get_passwd()
{
return passwd;
}

void consumer::set_money(float m)
{
money-=m;
}

void consumer::set_passwd(char pwd[])
{
strcpy(passwd,pwd);
}#include "function.h"
#include <string.h>
#include<stdlib.h>

void ATM::welcome()
{
times=0;
cout<<"$ 歡迎使用若雪銀行ATM自動取款機!~! "<<endl;

char pwd[8],num[20],ch;
int i=0;
do
{
i=0;
cout<<endl<<"請輸入卡號:";
do
{
cin.get(ch);
num[i++]=ch;
}while(ch!='\n');
num[i-1]='\0';

i=0;
cout<<"請輸入密碼:";
do
{
cin.get(ch);
pwd[i++]=ch;
}while(ch!='\n');
pwd[i-1]='\0';

if(!check_passwd(num,pwd))
{
cout<<"你輸入的卡號或密碼有誤, 請重新輸入"<<endl;
times++;
}
else
{
functionshow();
}
}while(times<3);
lock();
}

bool ATM::check_passwd(char num[],
char pwd[])
{
if(strcmp(num,cnsm.get_num())==0&&strcmp
(pwd,cnsm.get_passwd())==0)
return true;
else
return false;
}

void ATM::functionshow()
{
int n;

do
{
cout<<endl<<"請你輸入相應的操作序號進行操作: "<<endl;
cout<<"1) 修改密碼 "<<endl
<<"2) 取款 "<<endl
<<"3) 查詢余額 "<<endl
<<"4) 退出系統 "<<endl;
cout<<"$ >\\";
cin>>n;
while(n<1||n>4)
{
cout<<"請輸入正確的操作序號!"<<endl;
cout<<"$ >\\";
cin>>n;
}

switch(n)
{
case 1: change_passwd();
break;
case 2: fetchmoney();
break;
case 3: information();
break;
case 4: exitATM();
break;
}

}while(true);

}

void ATM::change_passwd()
{
char pwd[8],repwd[8];

times=0;
do
{
cout<<endl<<"請輸入舊密碼:";
cin>>pwd;
if(!check_passwd(cnsm.get_num(),pwd))
times++;
else
break;
}while(times<3);

if(times==3)
lock();

int t=0;
do
{
cout<<"請輸入新密碼:";
cin>>pwd;
cout<<"請再輸入一次新密碼:";
cin>>repwd;
if((t=strcmp(pwd,repwd))!=0)
cout<<"你輸入的兩次密碼不一樣, 請重新輸入!"<<endl;
}while(t!=0);

cnsm.set_passwd(pwd);
cout<<"密碼修改成功,請牢記!"<<endl;

}

void ATM::fetchmoney()
{
float m;
char ch;
do
{
cout<<endl<<"你要取多少錢:" <<"\n$>\\"<<endl ;
cin>>m;
while(m<=0)
{
cout<<"請輸入正確的數字!"<<endl;
cout<<"$ >\\ ";
cin>>m;
}

if(cnsm.get_money()-m<0)
{
cout<<"對不起,你的余額不足!"
<<endl;
}
else
{
cout<<endl<<"操作成功,請收好錢!" <<endl;
cnsm.set_money(m);
}
cout<<"是否要繼續該項操作:(Y/N) " <<endl;
cout<<"$ >\\ ";
cin>>ch;
while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y')
{
cout<<"$ >\\";
cin>>ch;
}

}while(ch=='y'||ch=='Y');

}

void ATM::information()
{
cout<<"**********************************"<<endl;
cout<<"*"<<endl;
cout<<"* 用戶姓名:"<<cnsm.get_name()<<endl;
cout<<"* 卡號: "<<cnsm.get_num()<<endl;
cout<<"* 余額: "<<cnsm.get_money()<<endl;
cout<<"**********************************"<<endl;

}

void ATM::lock()
{
cout<<endl<<"對不起,由於你的操作有誤, 你的卡已經被沒收! "<<endl;
exit(1);
}

void ATM::exitATM()
{
cout<<endl<<"感謝你對本銀行的支持, 歡迎下次光臨!"<<endl;
cout<<"請取卡……"<<endl;
exit(0);
}#include<iostream.h>
#include"function.h"

void main()
{
consumer c1("jim","12345",5200.3f,"123"); // 先構造一個用戶
ATM atm(c1);
atm.welcome();
}用C++語言也行的!

⑤ 如何用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);

}
}
}

⑥ Java編程實現程序用於模擬ATM取款機。

package demo;

import java.util.Scanner;

public class Test3 {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
int cnt=3;
String username = null;
String password = null;
double money = 1000;
String targetName = "admin33";
double targetMoney = 1000;
while(true){

if(username!=null&&password!=null){

if("admin".equals(username) && "123".equals(password)){
System.out.println("歡迎光臨");
while(true){
System.out.println("請選擇您的操作 1 取錢 2 存錢 3 轉賬 4 查詢 5 退出 ");
int n = scanner.nextInt();
if(n==1){//取錢
System.out.println("請輸入金額");
int getter = scanner.nextInt();
if(getter>=0){
if(getter<=5000){
if(getter<=money){
money-=getter;
}else{
System.out.println("余額不足");
}
}else{
System.out.println("單筆只能取5000及以下");
}
}else{
System.out.println("銀行不到給");
}
}else if(n==2){//存錢
System.out.println("請輸入金額");
int save = scanner.nextInt();
if(save>=0){
money+=save;
}
}else if(n==3){//轉賬
System.out.println("請輸入目標賬戶");
String target = scanner.next();
if(target.equals(targetName)){
System.out.println("請輸入金額");
int getter = scanner.nextInt();
if(getter>=0){
if(getter<=5000){
if(getter<=money){
money-=getter;
targetMoney+=getter;
}else{
System.out.println("余額不足");
}
}else{
System.out.println("單筆只能取5000及以下");
}
}else{
System.out.println("銀行不到給");
}
}
}else if(n==4){//查詢
System.out.println(money);
}else if(n==5){//退出
System.exit(0);
}else{
System.out.println("沒有該項服務");
}
}
}else{
cnt--;
System.out.println("輸入錯誤,您還有"+cnt+"次機會");
username=null;
password=null;
if(cnt<=0){
System.out.println("對不起,您的賬號被凍結,請到最近的營業廳解除凍結");
System.exit(0);
}
}
}else{
System.out.println("請輸入您的賬號");
username = scanner.next();
System.out.println("請輸入您的密碼");
password = scanner.next();
}
}
}
}

⑦ 求Java代碼 模擬簡易atm機

參考了別人的代碼。略作修改,已經很簡單了:

InfoATM.java:

publicclassInfoATM{

doublemoney=0;

publicInfoATM(doublecash){
super();
this.money=cash;
}
//存款的方法
publicvoidsave(doublecount){
money+=count;
}

//取款的方法
publicvoiddraw(doublecount){
money-=count;
}
publicdoublegetMoney(){
returnmoney;
}
publicvoidsetMoney(doublemoney){
this.money=money;
}

}

TestATM.java:

importjava.awt.BorderLayout;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JTextField;

{

=2531222181184935595L;
//主面板pnBasic是用來裝pnDate和標簽文字的。
privateJPanelpnBasic;
//添加到主面板中的中間pnDate面板是為了裝表單的。
privateJPanelpnDate;
//添加到主面板中的北邊pnLabel面板是為了裝歡迎詞的
privateJPanelpnLabel;
InfoATMatm=newInfoATM(0);

publicTestATM(){

pnBasic=newJPanel();
//主面板pnBasic是用來裝pnDate和標簽文字的。
pnDate=newJPanel(newGridLayout(2,2));
//pnDate面板是為了裝表單的。
pnLabel=newJPanel();

JLabeltop=newJLabel("歡迎來到中國銀行!");
pnLabel.add(top);
//先將數值添加在一個容器中並設置其在容器的右邊,在將容器添加在網格的第一格
JPaneljp1=newJPanel();

JLabelnumber=newJLabel("數值:");
finalJTextFieldbox=newJTextField(5);

jp1.add(number);
jp1.add(box);

JPaneljp2=newJPanel();
JButtoncreate=newJButton("新建銀行賬戶");
jp2.add(create);
JButtontake=newJButton("取款");
JButtonin=newJButton("存款");

pnDate.add(jp1);
pnDate.add(jp2);
pnDate.add(take);
pnDate.add(in);

//加一句下面的就好了
JPaneljpS=newJPanel();
finalJLabeltotal=newJLabel("您現在的賬戶余額是:0元");
jpS.add(total);

pnBasic.setLayout(newBorderLayout());

pnBasic.add(pnLabel,BorderLayout.NORTH);
pnBasic.add(pnDate,BorderLayout.CENTER);
pnBasic.add(jpS,BorderLayout.SOUTH);

setContentPane(pnBasic);
setBounds(400,250,500,500);
pack();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
pack();

in.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(box.getText()!=null&&box.getText()!=""){
try{
doublecount=Double.parseDouble(box.getText());
if(count>0){
atm.save(count);
total.setText("您現在的賬戶余額是:"+atm.getMoney()+"元");
box.setText("");
}
}catch(Exceptione1){
System.out.println("您輸入的數值必須是數字");
}

}
}
});

take.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(box.getText()!=null&&box.getText()!=""){
try{
doublecount=Double.parseDouble(box.getText());
if(count>=0&&count<=atm.getMoney()){
atm.draw(count);
total.setText("您現在的賬戶余額是:"+atm.getMoney()+"元");
box.setText("");
}else{
System.out.println("你的余額不足,取款失敗");
}
}catch(Exceptione1){
System.out.println("您輸入的數值必須是數字");
}
}
}
});

create.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
total.setText("您現在的賬戶余額是:0元");
atm.setMoney(0);
box.setText("");
}
});

}

publicstaticvoidmain(String[]args){
newTestATM();

}
}

⑧ 用java編寫多線程銀行ATM 模擬程序

先構建一個客戶端,再構建一個伺服器端,其實做一個簡單的界面,建立一個資料庫,調用SQl 語句,,實現單機,模擬多線程的就可以了,伺服器部分不做也可以模擬出來。。

PS:這不會是程序專題訓練一吧。。。

⑨ Java編程自動取款機步驟

Java編寫的模擬ATM取款機程序/*** @version 1.0
* @author Devil_Angel
* 該程序的功能為實現模擬銀行ATM自動取款機提款,查詢等功能.
*
*/import java.io.*;/*該類為實現客戶信息及部分功能*/
class Account {
private String code =null; //信用卡號
private String name =null; //客戶姓名
private String password=null; //客戶密碼
private double money =0.0; //卡里金額

/********************/
public Account(String code,String name,String password,double money)
{
this.code=code;
this.name=name;
this.password=password;
this.money=money;
}

protected String get_Code() {
return code;
}

protected String get_Name() {
return name;
}

protected String get_Password() {
return password;
}

public double get_Money() {
return money;
}

/*得到剩餘的錢的數目*/
protected void set_Balance(double mon) {
money -= mon;
}
}/**********實現具體取款機功能*********/
class ATM {
Account act;
// private String name;
// private String pwd;

public ATM() {
act=new Account("000000","Devil","123456",50000);
}

/***********歡迎界面***********/
protected void Welcome()
{
String str="---------------------------------";
System.out.print(str+"\n"+
"歡迎使用Angel模擬自動取款機程序.\n"+str+"\n");
System.out.print(" 1.>取款."+"\n"+
" 2.>查詢信息."+"\n"+
" 3.>密碼設置."+"\n"+
" 4.>退出系統."+"\n");
}

/**********登陸系統**********/
protected void Load_Sys() throws Exception
{
String card,pwd;
int counter=0;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入您的信用卡號:");
card=br.readLine();
System.out.println("請輸入您的密碼:");
pwd=br.readLine();

if(!isRight(card,pwd))
{
System.out.println("您的卡號或密碼輸入有誤.");
counter++;
}
else
SysOpter();

}while(counter<3);
Lock_Sys();
}

/**********系統操作**********/
protected void SysOpter() throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("請選擇您要操作的項目(1-4):");
num=br.read(); //num為ASICC碼轉換的整數
switch(num) {
case 49: BetBalance(); break;
case 50: Inqu_Info(); break;
case 51: Set_Password(); break;
case 52: Exit_Sys(); break;
}
System.exit(1);
}

/**********信息查詢**********/
protected void Inqu_Info() {
System.out.print("---------------------\n"+
act.get_Code()+"\n"+
act.get_Name()+"\n"+
act.get_Money()+"\n"+
"-----------------------");
}

/**********取款**********/
public void BetBalance() throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入您要取的數目:");
str=br.readLine();
str1=String.valueOf(act.get_Money());
if(str.compareTo(str1)>0) {
System.out.println("超過已有的錢數,請重新輸入您要取的數目:");
}
else {
/*操作成功*/
// act.set_Balance(str);
System.out.println("取款成功,請收好您的錢.");
Welcome();
SysOpter();
}
}while(true);

}

/**********判斷卡內是否有錢**********/
protected boolean isBalance() {
if(act.get_Money()<0) {
// System.out.println("對不起,您的錢數不夠或卡已透支.");
return false;
}
return true;
}

/********卡號密碼是否正確******/
protected boolean isRight(String card,String pwd)
{
if(act.get_Code().equals(card) && act.get_Password().equals(pwd))
return true;
else
return false;
}

/**********密碼修改**********/
protected void Set_Password() throws Exception
{
String pwd=null;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入舊密碼:");
pwd=br.readLine();
if(act.get_Password().equals(pwd))
{
do {
System.out.println("請輸入新密碼:");
String pwd1=br.readLine();
System.out.println("請再次輸入新密碼:");
String pwd2=br.readLine();
if(!pwd1.equals(pwd2))
{
System.out.println("兩次輸入不一致,請再次輸入.");
}
else
{
System.out.println("密碼修改成功,請使用新密碼.");
Welcome();
SysOpter();
}
}while(true);
}
}while(counter>3);

}

/**********鎖定機器**********/
protected void Lock_Sys() {
System.out.println("對不起,您的操作有誤,卡已被沒收.");
System.exit(1);
}

/**********結束系統**********/
protected void Exit_Sys() {
System.out.println("感謝您使用本系統,歡迎下次在來,再見!");
System.exit(1);
}

}public class Text
{
public static void main(String[] args) throws Exception
{
ATM atm=new ATM();
atm.Welcome();
atm.Load_Sys();
// atm.Exit_Sys();
}
} //模擬ATM取款機工作流程 import java.util.Scanner;public class Atm {
public Atm() {
}
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int password = 0;
int count = 0;
int choice = 0;
int type = 0;
int input = 0;
int acount = 1000;
boolean exit = false;
int flag = 0;

do{
System.out.println("請輸入您的密碼:");
password = sc.nextInt();
count++;
}while(password != 12345 && count<3);
if(password == 12345){
//密碼正確繼續後面的操作。
do{
System.out.println("請選擇您的操作,1.查詢 2.取款");
choice = sc.nextInt();
switch(choice){
case 1:
do{
System.out.println("請選擇帳戶類型:1. 美元 2. 人民幣");
type = sc.nextInt();
if(type == 1){
System.out.println("You have $"+acount+"!");
}else if(type == 2){
System.out.println("您有"+acount+"圓!");
}else{
System.out.println("類型選擇錯誤,請重新選擇!");
}
System.out.println("1.繼續 2.離開");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}while(type!=1 && type!=2);
break;
case 2: do{
System.out.println("請選擇帳戶類型:1. 美元 2. 人民幣");
if(type == 1){
System.out.println("Please input number of your money!");
input = sc.nextInt();
if(input > acount){
System.out.println("You have not enough money!");
}else{
System.out.println("You take care of your money!");
}
System.out.println("1.continue 2.exit");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}else if(type == 2){
System.out.println("請輸入您要取的金額!");
input = sc.nextInt();
if(input > acount){
System.out.println("您的余額不足!");
}else{
System.out.println("請妥善保管您的錢!");
acount = acount - input;
}
System.out.println("1.繼續 2.離開");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}else{
System.out.println("類型選擇錯誤,請重新選擇!");
}

}while(type!=1 && type!=2);
break;
default: System.out.println("類型選擇錯誤,請重新選擇!");
}
}while(choice!=1 && choice!=2 || exit == false);
}else{
//密碼錯誤,退出。
System.out.println("三次密碼錯誤,吞卡!");
}
}
}

閱讀全文

與JAVA程序ATM櫃員機模擬程序相關的資料

熱點內容
64位java內存 瀏覽:418
女程序員學習方法 瀏覽:383
工程數學線性代數pdf 瀏覽:681
提升程序員技術檔次的書 瀏覽:691
python詞雲圖txt格式 瀏覽:968
韓國料理pdf 瀏覽:227
什麼app就能知道自己的臉型 瀏覽:383
准了app月卡可以看什麼 瀏覽:140
雲伺服器開機要開30秒 瀏覽:646
php數組傳遞給js 瀏覽:640
在世紀的轉折點上pdf 瀏覽:857
變頻製冷壓縮機性能實驗 瀏覽:575
印刷哪個app好 瀏覽:367
安卓手機如何查看連接過的wifi密碼 瀏覽:461
chrpythonord 瀏覽:353
android切片 瀏覽:231
前端js調用php 瀏覽:591
文件夾res是什麼 瀏覽:488
linuxput命令 瀏覽:932
智能仿生演算法模擬退火 瀏覽:903