java简单银行取款代码 java编程银行存取款程序

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 = 0number = 1000number % 100 == 0){
System.out.println("用户取了"number"元 。交易完成");
moneyflag = false;
}else{
System.out.println("请重新输入金额");
}
}
break;
}else{
continue;
}
}
}
}
使用JAVA编写一个简单的银行存取款程序package com.lw.thread;
/*
银行账户类Account(不能透支) ,
包含账号id(10~16位数字),密码password(6位数字),户主姓名name,余额balence
*/
public class Account {
private String id;
private int password;
private String name;
private double balence;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getPassword() {
return password;
}
public void setPassword(int password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalence() {
return balence;
}
public void setBalence(double balence) {
this.balence = balence;
}
/*
* 默认构造账户信息为:1111111111111111,666666,钱三多 , 888888.88 。
*/
public Account() {
super();
this.id = "1111111111111111";
this.password = 666666;
this.name = "钱三多";
this.balence = 888888.88;
}
/*
* 另一个构造方法带4个参数分别初始化4个属性(带数据有效性验证) 。
*/
public Account(String id, int password, String name, double balence) {
this.id = id;
this.password = password;
this.name = name;
this.balence = balence;
}
/*
* 查询余额
*/
public static double selectMoney(Account account) {
return account.getBalence();
}
/*
* 存钱
*/
public static String setMoney(Account account, double balence) {
if (balence0) {
return "存钱失败 , 请正确放入!";
}
double d = balenceaccount.getBalence();
account.setBalence(d);
return "您存入了"balence"元,现账户余额为 "d;
}
/*
* 取钱
*/
public static String getMoney(Account account, double balence) {
double d = account.getBalence();
if (balenced) {
return "您的余额不足!";
}
account.setBalence(d - balence);
return "您取出了"balence"元,现账户余额为 "account.getBalence();
}
}
如何用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; icount; 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; icount2 - 1; i) {
System.out.print(""(char) buffer[i]);
}
System.out.println();
// 字符0 ~ 9对应ASCII值48 ~ 57
boolean flag = false;
for (int i = 0; icount2 - 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; icount2 - 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; icount2 - 1; i) {
System.out.print(""(char) buffer[i]);
}
System.out.println();
// 字符0 ~ 9对应ASCII值48 ~ 57
boolean flag = false;
for (int i = 0; icount2 - 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; icount2 - 1; i) {
System.out.print(""(char) buffer[i]);
num= (char) buffer[i];
}
yue= Double.valueOf(num);
System.out.print(" , 现在余额¥:"yue);
}
}
}
【java简单银行取款代码 java编程银行存取款程序】关于java简单银行取款代码和java编程银行存取款程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读