package demo;
目前創(chuàng)新互聯(lián)已為近千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁(yè)空間、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、涇川網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
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();
}
}
}
}
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");
}
}
參考了別人的代碼。略作修改,已經(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是用來(lái)裝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是用來(lái)裝pnDate和標(biāo)簽文字的。
pnDate?=?new?JPanel(new?GridLayout(2,?2));
//?pnDate面板是為了裝表單的。
pnLabel?=?new?JPanel();
JLabel?top?=?new?JLabel("歡迎來(lái)到中國(guó)銀行!");
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();
}
}
/** * @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ù)獲取全部
網(wǎng)頁(yè)標(biāo)題:模擬atm機(jī)java代碼 atm模擬程序
URL分享:http://muchs.cn/article20/dohhjco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、電子商務(wù)、用戶體驗(yàn)、搜索引擎優(yōu)化、網(wǎng)頁(yè)設(shè)計(jì)公司、定制開發(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)