大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

自动取款机代码java,自动取款机全称

Java编程实现程序用于模拟ATM取款机。

package demo;

目前创新互联建站已为上1000家的企业提供了网站建设、域名、雅安服务器托管网站托管运营、企业网站设计、遵义网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

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("请选择您的操作 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机代码

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("密码错误,请取卡");

break;

}

System.out.println("请输入你的密码");

String password = sc.next();

if(password.equals("111111")){

Boolean moneyflag = true;

while(moneyflag){

System.out.println("请输入金额");

int number = sc.nextInt();

if(number = 0 number = 1000 number % 100 == 0){

System.out.println("用户取了" + number + "元。交易完成");

moneyflag = false;

}else{

System.out.println("请重新输入金额");

}

}

break;

}else{

continue;

}

}

}

}

急急急~~求JAVA中用方法写出一个银行ATM取款机的代码怎么写!!

public class Card {

public String type; //卡的类型

public String cardCode; //卡号

public double money; //钱

/**

* 重写toString()方法

*/

public String toString(){

return "卡的类型:"+type+"\t卡号:"+cardCode+"\t余额:"+money;

}

}public class Person {

Card card;

/**

* 构造方法,一般用来初始化信息

* 此方法是创建对象时自动调用的

*

*/

public Person(){

card=new Card();

card.type="招商银行";

card.money=1000D;

}

/**

*

* @param money 你要取的钱

* @return 返回的是取到的钱

*/

public double getMoney(double money){

if( (card.money-money) =0){

card.money=card.money-money;//从卡中减去要取的钱,并重新改变卡中的余额

return money;

}else{

System.out.println("余额不足:请存款!");

return 0;

}

}

/**

* 存款

* @param money

*/

public void setMoney(double money){

if(money=0){

System.out.println("不能为0!");

}else

card.money=card.money+money;

}

/**

* 这个方法是输出客户卡的信息

*/

public void print(){

System.out.println(card);

}

}public class Text {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Person p=new Person();

p.card.cardCode="111100022222";

p.setMoney(1000);

double money=p.getMoney(2000);

System.out.println(p.card);

}

}

用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.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取款机程序

我现写的: import java.util.Scanner;public class ATM {

private static String theName = "admin";

private static String thePassword = "123456";

private static int balance = 10000;

public static void getBalance(){

System.out.println("当前余额:" + balance);

}

public static void drawMoney(Scanner sc){

int money = 0;

System.out.println("请输入取款金额:");

money = sc.nextInt();

String type = "";

if (balance 0) {

if (balance = money) {

if (money = 5000) {

balance = balance - money;

type = "请在30秒内提取现金...\n剩余余额:"+balance;

} else if (money = 0) {

type = "金额错误";

} else {

type = "超出最大限制金额";

}

} else {

type = "超出最大余额";

}

} else {

type = "余额不足";

}

System.out.println(type);

}

public static void bankMoney(Scanner sc){

int money = 0;

System.out.println("请输入存储金额:");

money = sc.nextInt();

String type = "";

if (money 0) {

balance = balance + money;

type = "存储成功,现有余额:" + balance;

} else {

type = "存储金额不能为负";

}

System.out.println(type);

}

public static void updatePass(Scanner sc){

String oldPass = "";

String newPass1 = "";

String newPass2 = "";

while(true){

System.out.println("请输入原密码:");

oldPass = sc.next();

if (oldPass.equals(thePassword)) {

break;

} else {

System.out.println("密码错误,请重新输入");

}

}

while(true){

System.out.println("请输入新密码");

newPass1 = sc.next();

System.out.println("再次输入");

newPass2 = sc.next();

if (newPass1.equals(newPass2)) {

if (!isSame(newPass1)) {

thePassword = newPass1;

System.out.println("修改成功");

break;

} else {

System.out.println("所有字符不能相同,重新输入");

}

} else {

System.out.println("两次输入不一致,重新输入");

}

}

}

public static boolean isSame(String string){

boolean bool = false;

for (int i = 0; i string.length() - 1; i++) {

char char1 = string.charAt(i);

for (int j = i + 1; j string.length(); j++) {

char char2 = string.charAt(j);

if (char1 == char2) {

bool = true;

break;

}

}

}

return bool;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while(true){

String name = "";

String password = "";

System.out.println("请输入账号:");

name = sc.next();

System.out.println("请输入密码:");

password = sc.next();

if (name.equals(theName) password.equals(thePassword)) {

break;

} else {

System.out.println("账号或密码错误,请重新输入!");

}

}

while(true){

int operate = 0;

System.out.println("请选择你要进行的操作:\n1、查询 2、取款 3、存款 4、修改密码 0、退出");

operate = sc.nextInt();

if (0 == operate) {

System.out.println("谢谢使用!");

break;

} else if (1 == operate) {

getBalance();

} else if (2 == operate) {

drawMoney(sc);

} else if (3 == operate) {

bankMoney(sc);

} else if (4 == operate) {

updatePass(sc);

}

}

}

}


文章题目:自动取款机代码java,自动取款机全称
分享地址:http://dzwzjz.com/article/hspcii.html
在线咨询
服务热线
服务热线:028-86922220
TOP