package arraylist;
成都創(chuàng)新互聯(lián)公司長(zhǎng)期為上1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為銅官企業(yè)提供專業(yè)的做網(wǎng)站、成都網(wǎng)站建設(shè),銅官網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
import java.util.Scanner;
public class AtmDemo
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
Boolean flag = true;
int times = 0;
while(flag){
times++;
if(times == 4){
System.out.println("密碼錯(cuò)誤,請(qǐng)取卡");
break;
}
System.out.println("請(qǐng)輸入你的密碼");
String password = sc.next();
if(password.equals("111111")){
Boolean moneyflag = true;
while(moneyflag){
System.out.println("請(qǐng)輸入金額");
int number = sc.nextInt();
if(number = 0 number = 1000 number % 100 == 0){
System.out.println("用戶取了" + number + "元。交易完成");
moneyflag = false;
}else{
System.out.println("請(qǐng)重新輸入金額");
}
}
break;
}else{
continue;
}
}
}
}
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!=nullpassword!=null){
if("admin".equals(username) "123".equals(password)){
System.out.println("歡迎光臨");
while(true){
System.out.println("請(qǐng)選擇您的操作 1 取錢 2 存錢 3 轉(zhuǎn)賬 4 查詢 5 退出 ");
int n = scanner.nextInt();
if(n==1){//取錢
System.out.println("請(qǐng)輸入金額");
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("請(qǐng)輸入金額");
int save = scanner.nextInt();
if(save=0){
money+=save;
}
}else if(n==3){//轉(zhuǎn)賬
System.out.println("請(qǐng)輸入目標(biāo)賬戶");
String target = scanner.next();
if(target.equals(targetName)){
System.out.println("請(qǐng)輸入金額");
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("沒有該項(xiàng)服務(wù)");
}
}
}else{
cnt--;
System.out.println("輸入錯(cuò)誤,您還有"+cnt+"次機(jī)會(huì)");
username=null;
password=null;
if(cnt=0){
System.out.println("對(duì)不起,您的賬號(hào)被凍結(jié),請(qǐng)到最近的營(yíng)業(yè)廳解除凍結(jié)");
System.exit(0);
}
}
}else{
System.out.println("請(qǐng)輸入您的賬號(hào)");
username = scanner.next();
System.out.println("請(qǐng)輸入您的密碼");
password = scanner.next();
}
}
}
}
很簡(jiǎn)單的例子,我把代碼貼出來吧
import java.util.Scanner;
public class ATM {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in = null;
int result;
double drawMoney;
double depositMoney;
Account account = new Account();
while (true) {
System.out.println("☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆(ABC)中國(guó)農(nóng)業(yè)銀行ATM自動(dòng)存取款機(jī)☆☆☆☆☆☆☆☆☆☆☆☆☆");
System.out.println("\n\t\t\t\t1.存款業(yè)務(wù)");
System.out.println("\n\t\t\t\t2.取款業(yè)務(wù)");
System.out.println("\n\t\t\t\t3.查詢余額");
System.out.println("\n\t\t\t\t4.退出ATM系統(tǒng)");
System.out.println("\n☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆中國(guó)農(nóng)業(yè)銀行歡迎您的使用☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆");
in = new Scanner(System.in);
switch (in.nextInt()) {
case 1:
System.out.println("請(qǐng)輸入您的存款數(shù)額!");
depositMoney = in.nextDouble();
if(depositMoney 0)
System.out.println("您的輸入無效,請(qǐng)重新輸入!");
result = account.deposit(depositMoney);
if(result == 0){
System.out.println("存款業(yè)務(wù)完成,是否顯示余額?Y/N");
if("Y".equalsIgnoreCase(in.next())){
System.out.println("您當(dāng)前的余額為:"+account.checkCurrent());
}else {
break;
}
}else {
System.out.println("無法完成交易!");
break;
}
break;
case 2:
System.out.println("請(qǐng)輸入您的取款數(shù)額!");
drawMoney = in.nextDouble();
if (drawMoney 0) {
System.out.println("您的輸入無效,請(qǐng)重新輸入!");
}
result = account.withDraw(drawMoney);
if (result == 0) {
System.out.println("存款業(yè)務(wù)完成,是否顯示余額?Y/N");
if("Y".equalsIgnoreCase(in.next())){
System.out.println("您當(dāng)前的余額為:"+account.checkCurrent());
}else {
break;
}
} else {
System.out.println("無法完成交易!");
break;
}
case 3:
System.out.println("您當(dāng)前的余額為:"+account.checkCurrent());
break;
case 4:
break;
default:
break;
}
}
}
}
public class Account {
private double currentMoney;//當(dāng)前余額
public double getCurrentMoney() {
return currentMoney;
}
public void setCurrentMoney(double currentMoney) {
if (currentMoney 0) {
this.currentMoney = currentMoney;
}
}
/**
* 取款業(yè)務(wù)
* @param drawMoney
* @return 0代表成功,1代表失敗
*/
public int withDraw(double drawMoney) {
if (currentMoney 0 drawMoney = currentMoney) {
currentMoney -= drawMoney;
} else {
System.out.println("您的余額已不足!");
return 1;
}
return 0;
}
/**
* 存款業(yè)務(wù)
* @param depositMoney
* @return 0代表成功,1代表失敗
*/
public int deposit(double depositMoney) {
if (depositMoney 0) {
currentMoney += depositMoney;
return 0;
}else {
System.out.println("您提交的存款為負(fù)數(shù),無法完成存款交易");
return -1;
}
}
/**
* 查詢余額業(yè)務(wù)
* @return
*/
public double checkCurrent() {
return currentMoney;
}
}
package demo;
import java.io.*;
/*該類為實(shí)現(xiàn)客戶信息及部分功能*/
class Account {
private String code =null; //信用卡號(hào)
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;
}
/*得到剩余的錢的數(shù)目*/
protected void set_Balance(double mon) {
money -= mon;
}
/*得到剩余的錢的數(shù)目*/
protected void set_Deposit(double mon) {
money += mon;
}
}
/**********實(shí)現(xiàn)具體取款機(jī)功能*********/
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模擬自動(dòng)取款機(jī)程序.\n"+str+"\n");
System.out.print(" 1.取款."+"\n"+
" 2.存款."+"\n"+
" 3.查詢信息."+"\n"+
" 4.密碼設(shè)置."+"\n"+
" 5.退出系統(tǒng)."+"\n");
}
/**********登陸系統(tǒng)**********/
protected void Load_Sys() throws Exception
{
String card,pwd;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請(qǐng)輸入您的信用卡號(hào):");
card=br.readLine();
System.out.println("請(qǐng)輸入您的密碼:");
pwd=br.readLine();
if(!isRight(card,pwd))
{
System.out.println("您的卡號(hào)或密碼輸入有誤.");
counter++;
}
else
Welcome();
SysOpter();
}while(counter3);
Lock_Sys();
}
/**********系統(tǒng)操作**********/
protected void SysOpter() throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("請(qǐng)選擇您要操作的項(xiàng)目(1-5):");
num=br.read(); //num為ASICC碼轉(zhuǎn)換的整數(shù)
switch(num) {
case 49: BetBalance(); break;
case 50: Deposit(); break;
case 51: Inqu_Info(); break;
case 52: Set_Password(); break;
case 53: Exit_Sys(); break;
}
System.exit(1);
}
/**********信息查詢
* @throws Exception **********/
protected void Inqu_Info() throws Exception {
System.out.print("---------------------\n"+
act.get_Code()+"\n"+
act.get_Name()+"\n"+
act.get_Money()+"\n"+
"-----------------------");
Welcome();
SysOpter();
}
/**********取款**********/
public void BetBalance() throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int count=0;//取款錯(cuò)誤超過3次自動(dòng)退出
do {
System.out.println("請(qǐng)輸入您要取的數(shù)目:");
str=br.readLine();
str1=String.valueOf(act.get_Money());
System.out.println(str1);
if(Double.parseDouble(str)Double.parseDouble(str1)) {
count++;
System.out.println("超過已有的錢數(shù),請(qǐng)重新輸入您要取的數(shù)目:");
if(count=3){
System.out.println("超過已有的錢數(shù),請(qǐng)重新輸入您要取的數(shù)目:");
Exit_Sys();
}
}
else {
/*操作成功*/
act.set_Balance(Double.parseDouble(str));
System.out.println("取款成功,請(qǐng)收好您的錢.");
Welcome();
SysOpter();
}
}while(true);
}
/*******存款********/
public void Deposit() throws Exception{
String str=null;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請(qǐng)輸入您要存的數(shù)目:");
str=br.readLine();
/*操作成功*/
act.set_Deposit(Double.parseDouble(str));
System.out.println("取款成功,請(qǐng)收好您的錢.");
Welcome();
SysOpter();
}while(true);
}
/**********判斷卡內(nèi)是否有錢**********/
protected boolean isBalance() {
if(act.get_Money()0) {
System.out.println("對(duì)不起,您的錢數(shù)不夠或卡已透支.");
return false;
}
return true;
}
/********卡號(hào)密碼是否正確******/
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("請(qǐng)輸入舊密碼:");
pwd=br.readLine();
if(act.get_Password().equals(pwd))
{
do {
System.out.println("請(qǐng)輸入新密碼:");
String pwd1=br.readLine();
System.out.println("請(qǐng)?jiān)俅屋斎胄旅艽a:");
String pwd2=br.readLine();
if(!pwd1.equals(pwd2))
{
System.out.println("兩次輸入不一致,請(qǐng)?jiān)俅屋斎?");
}
else
{
System.out.println("密碼修改成功,請(qǐng)使用新密碼.");
Welcome();
SysOpter();
}
}while(true);
}
}while(counter3);
}
/**********鎖定機(jī)器**********/
protected void Lock_Sys() {
System.out.println("對(duì)不起,您的操作有誤,卡已被沒收.");
System.exit(1);
}
/**********結(jié)束系統(tǒng)**********/
protected void Exit_Sys() {
System.out.println("感謝您使用本系統(tǒng),歡迎下次在來,再見!");
System.exit(1);
}
}
public class Text
{
public static void main(String[] args) throws Exception
{
ATM atm=new ATM();
atm.Load_Sys();
// atm.Exit_Sys();
}
}
卡號(hào):00000 密碼123456 默認(rèn)50000金額。簡(jiǎn)單版本的存取款。
名稱欄目:java代碼編寫atm Java代碼編寫論壇軟件
文章分享:http://m.kartarina.com/article20/dogehjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、定制網(wǎng)站、微信公眾號(hào)、網(wǎng)站營(yíng)銷、網(wǎng)頁(yè)設(shè)計(jì)公司、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)