网站建设资讯

NEWS

网站建设资讯

自助取款机的代码JAVA 自动取款机代码

用java编写的ATM机源代码

/** * @author admin * 该程序的功能为实现模拟银行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(counter3); Lock_Sys(); } 回复获取全部

为宁国等地区用户提供了全套网页设计制作服务,及宁国网站建设行业解决方案。主营业务为成都网站设计、成都网站制作、宁国网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

使用Java语言中(类和对象)编写: ATM自动存取款机的程序?

很简单的例子,我把代码贴出来吧

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)中国农业银行ATM自动存取款机☆☆☆☆☆☆☆☆☆☆☆☆☆");

System.out.println("\n\t\t\t\t1.存款业务");

System.out.println("\n\t\t\t\t2.取款业务");

System.out.println("\n\t\t\t\t3.查询余额");

System.out.println("\n\t\t\t\t4.退出ATM系统");

System.out.println("\n☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆中国农业银行欢迎您的使用☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆");

in = new Scanner(System.in);

switch (in.nextInt()) {

case 1:

System.out.println("请输入您的存款数额!");

depositMoney = in.nextDouble();

if(depositMoney 0)

System.out.println("您的输入无效,请重新输入!");

result = account.deposit(depositMoney);

if(result == 0){

System.out.println("存款业务完成,是否显示余额?Y/N");

if("Y".equalsIgnoreCase(in.next())){

System.out.println("您当前的余额为:"+account.checkCurrent());

}else {

break;

}

}else {

System.out.println("无法完成交易!");

break;

}

break;

case 2:

System.out.println("请输入您的取款数额!");

drawMoney = in.nextDouble();

if (drawMoney 0) {

System.out.println("您的输入无效,请重新输入!");

}

result = account.withDraw(drawMoney);

if (result == 0) {

System.out.println("存款业务完成,是否显示余额?Y/N");

if("Y".equalsIgnoreCase(in.next())){

System.out.println("您当前的余额为:"+account.checkCurrent());

}else {

break;

}

} else {

System.out.println("无法完成交易!");

break;

}

case 3:

System.out.println("您当前的余额为:"+account.checkCurrent());

break;

case 4:

break;

default:

break;

}

}

}

}

public class Account {

private double currentMoney;//当前余额

public double getCurrentMoney() {

return currentMoney;

}

public void setCurrentMoney(double currentMoney) {

if (currentMoney 0) {

this.currentMoney = currentMoney;

}

}

/**

* 取款业务

* @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;

}

/**

* 存款业务

* @param depositMoney

* @return 0代表成功,1代表失败

*/

public int deposit(double depositMoney) {

if (depositMoney 0) {

currentMoney += depositMoney;

return 0;

}else {

System.out.println("您提交的存款为负数,无法完成存款交易");

return -1;

}

}

/**

* 查询余额业务

* @return

*/

public double checkCurrent() {

return currentMoney;

}

}

如何用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编程自动取款机步骤

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(counter3);

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(counter3);

}

/**********锁定机器**********/

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 count3);

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机

参考了别人的代码。略作修改,已经很简单了:

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和标签文字的。

private JPanel pnBasic;

// 添加到主面板中的中间 pnDate面板是为了装表单的。

private JPanel pnDate;

// 添加到主面板中的北边 pnLabel面板是为了装欢迎词的

private JPanel pnLabel;

InfoATM atm = new InfoATM(0);

public TestATM() {

pnBasic = new JPanel();

// 主面板pnBasic是用来装pnDate和标签文字的。

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

// pnDate面板是为了装表单的。

pnLabel = new JPanel();

JLabel top = new JLabel("欢迎来到中国银行!");

pnLabel.add(top);

// 先将数值添加在一个容器中并设置其在容器的右边,在将容器添加在网格的第一格

JPanel jp1 = new JPanel();

JLabel number = new JLabel("数值:");

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("您现在的账户余额是: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("您现在的账户余额是:" + atm.getMoney() + "元");

box.setText("");

}

} catch (Exception e1) {

System.out.println("您输入的数值必须是数字");

}

}

}

});

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("您现在的账户余额是:" + atm.getMoney() + "元");

box.setText("");

} else {

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

}

} catch (Exception e1) {

System.out.println("您输入的数值必须是数字");

}

}

}

});

create.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

total.setText("您现在的账户余额是:0元");

atm.setMoney(0);

box.setText("");

}

});

}

public static void main(String[] args) {

new TestATM();

}

}


当前题目:自助取款机的代码JAVA 自动取款机代码
标题来源:http://cdweb.net/article/dodspgp.html