java模擬atm代碼 atm機(jī)模擬系統(tǒng)java

Java編程實(shí)現(xiàn)程序用于模擬ATM取款機(jī)。

package demo;

我們提供的服務(wù)有:成都做網(wǎng)站、成都網(wǎng)站制作、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、敦煌ssl等。為千余家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的敦煌網(wǎng)站制作公司

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è)廳解除凍結(jié)");

System.exit(0);

}

}

}else{

System.out.println("請(qǐng)輸入您的賬號(hào)");

username = scanner.next();

System.out.println("請(qǐng)輸入您的密碼");

password = scanner.next();

}

}

}

}

求Java代碼 模擬簡(jiǎn)易atm機(jī)

參考了別人的代碼。略作修改,已經(jīng)很簡(jiǎn)單了:

InfoATM.java:

public?class?InfoATM?{

double?money?=?0;

public?InfoATM(double?cash)?{

super();

this.money?=?cash;

}

//?存款的方法

public?void?save(double?count)?{

money?+=?count;

}

//?取款的方法

public?void?draw(double?count)?{

money?-=?count;

}

public?double?getMoney()?{

return?money;

}

public?void?setMoney(double?money)?{

this.money?=?money;

}

}

TestATM.java:

import?java.awt.BorderLayout;

import?java.awt.GridLayout;

import?java.awt.event.ActionEvent;

import?java.awt.event.ActionListener;

import?javax.swing.JButton;

import?javax.swing.JFrame;

import?javax.swing.JLabel;

import?javax.swing.JPanel;

import?javax.swing.JTextField;

public?class?TestATM?extends?JFrame?{

private?static?final?long?serialVersionUID?=?2531222181184935595L;

//?主面板pnBasic是用來裝pnDate和標(biāo)簽文字的。

private?JPanel?pnBasic;

//?添加到主面板中的中間?pnDate面板是為了裝表單的。

private?JPanel?pnDate;

//?添加到主面板中的北邊?pnLabel面板是為了裝歡迎詞的

private?JPanel?pnLabel;

InfoATM?atm?=?new?InfoATM(0);

public?TestATM()?{

pnBasic?=?new?JPanel();

//?主面板pnBasic是用來裝pnDate和標(biāo)簽文字的。

pnDate?=?new?JPanel(new?GridLayout(2,?2));

//?pnDate面板是為了裝表單的。

pnLabel?=?new?JPanel();

JLabel?top?=?new?JLabel("歡迎來到中國銀行!");

pnLabel.add(top);

//?先將數(shù)值添加在一個(gè)容器中并設(shè)置其在容器的右邊,在將容器添加在網(wǎng)格的第一格

JPanel?jp1?=?new?JPanel();

JLabel?number?=?new?JLabel("數(shù)值:");

final?JTextField?box?=?new?JTextField(5);

jp1.add(number);

jp1.add(box);

JPanel?jp2?=?new?JPanel();

JButton?create?=?new?JButton("新建銀行賬戶");

jp2.add(create);

JButton?take?=?new?JButton("取款");

JButton?in?=?new?JButton("存款");

pnDate.add(jp1);

pnDate.add(jp2);

pnDate.add(take);

pnDate.add(in);

//?加一句下面的就好了

JPanel?jpS?=?new?JPanel();

final?JLabel?total?=?new?JLabel("您現(xiàn)在的賬戶余額是:0?元");

jpS.add(total);

pnBasic.setLayout(new?BorderLayout());

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(new?ActionListener()?{

public?void?actionPerformed(ActionEvent?e)?{

if?(box.getText()?!=?null??box.getText()?!=?"")?{

try?{

double?count?=?Double.parseDouble(box.getText());

if?(count??0)?{

atm.save(count);

total.setText("您現(xiàn)在的賬戶余額是:"?+?atm.getMoney()?+?"元");

box.setText("");

}

}?catch?(Exception?e1)?{

System.out.println("您輸入的數(shù)值必須是數(shù)字");

}

}

}

});

take.addActionListener(new?ActionListener()?{

public?void?actionPerformed(ActionEvent?e)?{

if?(box.getText()?!=?null??box.getText()?!=?"")?{

try?{

double?count?=?Double.parseDouble(box.getText());

if?(count?=?0??count?=?atm.getMoney())?{

atm.draw(count);

total.setText("您現(xiàn)在的賬戶余額是:"?+?atm.getMoney()?+?"元");

box.setText("");

}?else?{

System.out.println("你的余額不足,取款失敗");

}

}?catch?(Exception?e1)?{

System.out.println("您輸入的數(shù)值必須是數(shù)字");

}

}

}

});

create.addActionListener(new?ActionListener()?{

public?void?actionPerformed(ActionEvent?e)?{

total.setText("您現(xiàn)在的賬戶余額是:0元");

atm.setMoney(0);

box.setText("");

}

});

}

public?static?void?main(String[]?args)?{

new?TestATM();

}

}

java atm機(jī)代碼

package arraylist;

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;

}

}

}

}

用java編寫的ATM機(jī)源代碼

/** * @author admin * 該程序的功能為實(shí)現(xiàn)模擬銀行ATM自動(dòng)取款機(jī)提款,查詢等功能. */ 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í)現(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.密碼設(shè)置." "\n" " 4.退出系統(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 SysOpter(); }while(counter3); Lock_Sys(); } 回復(fù)獲取全部

java 模擬ATM系統(tǒng)代碼求教

你太強(qiáng)了。。很多東西你都沒有做,,例如你卡里只有10元,你去取1000000,會(huì)允許? getmoney()方法里面 sum = money + index1; 你寫漏1了。 最后你在兩個(gè)方法里面都沒有把錢賦給你原來的money這個(gè)屬性,都要添加一句:money=sum 或者是money = index + money;

急求JAVA模擬ATM機(jī)程序代碼,不要太復(fù)雜.

import java.util.*;

public class ATM {

static int people=123456;

static int mima=123456;

static int yue=10000;

static Scanner in=null;

public ATM(int people,int mima){

this.mima=mima;

}

public static void main(String[] args) {

chongxindenglu();

int count=1;

while(count!=0){

System.out.println("1、查詢余額");

System.out.println("2、取款");

System.out.println("3、存款");

System.out.println("4、修改密碼");

System.out.println("5、重新登錄");

count=in.nextInt();

switch(count){

case 1: System.out.println(10000); System.out.println(); break;

case 2: quKuan(); break;

case 3: cunKuan(); break;

case 4: xiugai(); break;

case 5: chongxindenglu();

}

}

}

public static void quKuan(){

System.out.println("請(qǐng)輸入取款金額:");

int qukuanjine=in.nextInt();

if(qukuanjine5000){

System.out.println("取款金額不能大于5000"+"\n");

}else{

if(qukuanjine%100!=0){

System.out.println("取款金額必須為100的整數(shù)倍"+"\n");

}else{

yue=yue-qukuanjine;

System.out.println("您取出了"+qukuanjine+"元,您現(xiàn)在的余額為:"+yue+"元"+"\n");

}

}

}

public static void cunKuan(){

System.out.println("請(qǐng)輸入存款金額");

int cunkuanjine=in.nextInt();

if(cunkuanjine0){

System.out.println("存款金額不能小于0");

}else{

yue=yue+cunkuanjine;

System.out.println("您已成功存入:"+cunkuanjine+"元,您現(xiàn)在總余額為:"+yue+"元"+"\n");

}

}

public static void xiugai(){

System.out.println("請(qǐng)輸入您的密碼:");

int mima1=in.nextInt();

if(mima1==mima){

System.out.println("請(qǐng)輸入新密碼:");

mima=in.nextInt();

System.out.println("您的密碼已修改為:"+mima+"\n");

}else{

System.out.println("密碼輸入錯(cuò)誤:"+"\n");

}

}

public static void chongxindenglu(){

in=new Scanner(System.in);

System.out.println("請(qǐng)輸入登錄帳號(hào):");

int denglupeople=in.nextInt();

System.out.println("請(qǐng)輸入登錄密碼:");

int denglumima=in.nextInt();

if(denglupeople==people denglumima==mima)

System.out.println("帳號(hào)登錄成功"+"\n");

else

System.out.println("密碼輸入錯(cuò)誤,登錄失敗"+"\n");

}

}

當(dāng)前題目:java模擬atm代碼 atm機(jī)模擬系統(tǒng)java
鏈接分享:http://www.muchs.cn/article24/docsije.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、響應(yīng)式網(wǎng)站靜態(tài)網(wǎng)站、網(wǎng)站制作、外貿(mào)建站、軟件開發(fā)

廣告

聲明:本網(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)

微信小程序開發(fā)