
正文
java银行取钱代码 java编程银行存取款程序
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
使用JAVA编写一个简单的银行存取款程序
package com.lw.thread;
/*
银行账户类Account(不能透支)java银行取钱代码,
包含账号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;
}
/*
* 默认构造账户信息为java银行取钱代码: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 (balence 0) {
return "存钱失败,请正确放入!";
}
double d = balence + account.getBalence();
account.setBalence(d);
return "您存入了" + balence + "元,现账户余额为+" + d;
}
/*
* 取钱
*/
public static String getMoney(Account account, double balence) {
double d = account.getBalence();
if (balence d) {
return "您的余额不足!";
}
account.setBalence(d - balence);
return "您取出了" + balence + "元,现账户余额为+" + account.getBalence();
}
}
相关问答
Q1: JAVA 简单银行系统的代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AccountDemo {
public static double MONEY = 0;// 初始化金额是100元。
public static void main(String[] args) {
final String USER_NAME = "zhangsan";// 用户名
final String PASSWORD = "123456";// 密码
while (true) {
System.out.print("请输入用户名:");
String user_name = getString();
System.out.print("请输入密码:");
String password = getString();
if (user_name != null user_name.equals(USER_NAME)
password != null password.equals(PASSWORD)) {
System.out.println("登陆成功java银行取钱代码!你要干什么java银行取钱代码?");
while (true) {
System.out.println("1:存款");
System.out.println("2:取款");
System.out.println("3:查询余额");
System.out.println("q:退出程序");
System.out.print("请选择:");
String userIn = getString();
int in = 0;
if (userIn != null userIn.equals("1")) {
in = Integer.parseInt(userIn);
} else if (userIn != null userIn.equals("2")) {
in = Integer.parseInt(userIn);
} else if (userIn != null userIn.equals("3")) {
in = Integer.parseInt(userIn);
} else if (userIn != null
userIn.trim().toUpperCase().equals("Q")) {
in = 4;
} else {
System.out.println("你输入的指令不正确java银行取钱代码!请重新输入。");
continue;
}
switch (in) {
case 1:
double add_money = 0;
while (true) {
System.out.print("请输入你要存入的金额:");
try {
add_money = Double.parseDouble(getString());
} catch (Exception e) {
System.out.println("金额输入不正确!");
continue;
}
break;
}
MONEY += add_money;
System.out.println("存入的金额是" + add_money
+ "\r\n请选择你要的操作:");
break;
case 2:
double money = 0;
while (true) {
System.out.print("请输入你要取出的金额:");
try {
money = Double.parseDouble(getString());
} catch (Exception e) {
System.out.println("金额输入不正确!");
continue;
}
if (money MONEY) {
System.out.println("取出的金额大于现有存款,请重新输入要取出的金额!");
continue;
}
break;
}
MONEY -= money;
System.out.println("取出的金额是" + money + "\r\n请选择你要的操作:");
break;
case 3:
System.out.println("你的余额是:" + MONEY + "\r\n请选择你要的操作:");
break;
case 4:
System.out.println("程序退出!");
return;
}
}
} else {
System.out.println("错误:用户名与密码不匹配!\r\n");
System.out.println("按任意键:重新输入用户名和密码。");
System.out.println("q:退出程序。");
System.out.print("请选择:");
String in = getString();
if (in.trim().toUpperCase().equals("Q")) {
break;
}
}
}
}
public static String getString() {
String str = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
Q2: 用java线程同步实现银行取款和存款。
java银行取钱代码你java银行取钱代码的代码问题很多!
帮java银行取钱代码你修改后:
class Account {
private static float Balance = 200f;//线程共享的钱
public synchronized static void deposit(float amt) {
Balance = Balance + amt;
try {
Thread.sleep(10);// 模拟其它处理所需要的时间java银行取钱代码,比如刷新数据库等
}
catch (InterruptedException e) {
}
}
public static float getBalance() {
return Balance;
}
public static void setBalance(float balance) {
Balance = balance;
}
public synchronized static void withdraw(float bmt) {
Balance -= bmt;
try {
Thread.sleep(10);// 模拟其它处理所需要的时间java银行取钱代码,比如刷新数据库等
}
catch (InterruptedException e) {
}
}
String name;
public Account(String name) {
this.name = name;
}
}
public class AccountTest {
public static void main(String[] args) {
Customer customerA = new Customer("A");
Customer customerB = new Customer("B");
customerA.start();
customerB.start();
System.out.println();
try {
customerA.join();//等待A线程执行完毕
customerB.join();//等待B线程执行完毕
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("最后总钱数:" + Account.getBalance());
}
}
class Customer extends Thread {
public Customer(String string) {
super(string);
}
@Override
public void run() {
System.out.println(currentThread().getName());
if (currentThread().getName().equals("A"))
Account.deposit(100.0f);//A线程加100
else if (currentThread().getName().equals("B"))
Account.withdraw(50.0f);//B线程减50
}
}
Q3: JAVA高手来,题目是:自定义异常类,实现银行的存钱和取钱业务
3个类,开始...
1,
/**
*
* 自定义异常类
*
*/
public class MyException extends Exception {
//验证交易类型正确性
public void TransactionsInfo(){
System.out.println("交易失败,只能输入0或者1");
}
//验证金额正确性
public void amountInfo(){
System.out.println("交易失败,输入金额不能为负数或者字符");
}
}
2,
public class User {
/**
* 用户信息类
*/
private String name; //用户名
private float amount; //用户金额
public User(String name,float amount){
this.name = name;
this.amount = amount;
}
public float getAmount() {
return amount;
}
public void setAmount(float amount) {
this.amount = amount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
// 交易的方法,需要接受两个参数,一个是代表交易方式(取款,或者存款,),一个代表交易金额
public User Transactions() throws MyException{
System.out.println("请输入您的交易方式.0代表存款,1代表取款");//提示用户交易方式
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
String flag = null;
try {
flag = br1.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if("0".equals(flag)){
}else if("1".equals(flag)){
amount=-amount;//因为1代表取款,所以变成负数
}else{
new MyException().TransactionsInfo(); //打印类型错误
return this;
}
String amountString = null;
try {
amountString = br2.readLine();
} catch (IOException e) {
e.printStackTrace();
}
float amount = 0.0f;
try{
amount = Float.parseFloat(amountString);
}catch(Exception ex){
throw new MyException();
}
this.amount = this.amount+amount;//交易
return this; //返回用户信息
}
}
3,
public class MoneyTest {
/**
* 测试类
* @param args
*/
public static void main(String[] args){
User user = new User("张三",123.4f); //测试用户
System.out.println("用户"+user.getName()+"交易前的金额为:"+user.getAmount());
try {
user.Transactions();
} catch (MyException e) {
// TODO Auto-generated catch block
e.amountInfo();
}//调用方法
System.out.println("交易后的金额为"+user.getAmount());
}
}
Q4: 用JAVA编程设计一个银行账户类,其中包括以下内容,并用字符界面模拟存款和取款过程。
import java.util.Scanner;
public class ZH {
private String zh;//账户
private String password;//密码
private String openTime;//开户时间
private String sfz;//身份证号
private double je;//存款金额
public String getZh() {
return zh;
}
public void setZh(String zh) {
this.zh = zh;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getOpenTime() {
return openTime;
}
public void setOpenTime(String openTime) {
this.openTime = openTime;
}
public String getSfz() {
return sfz;
}
public void setSfz(String sfz) {
this.sfz = sfz;
}
public double getJe() {
return je;
}
public void setJe(double je) {
this.je = je;
}
//存款方法
public void ck(double je){
this.je=this.je+je;//存入的金额加上原有的金额
}
//取款方法
public void qk(double je){
if(jethis.je){//取款金额大于余额
System.out.println("存款余额不足");
}else{
this.je=this.je-je;//原有的金额减去取出的金额
}
}
public static void main(String[] args) {
ZH zh = new ZH();//初始化一个账户信息
zh.setJe(10000.0);//向zh账户添加余额
zh.setOpenTime("2013.12.3");//向zh账户添加开发时间
zh.setPassword("123456");//向zh账户添加密码
zh.setSfz("123456789");//向zh账户添加身份证
zh.setZh("zhangsan");//向zh账户添加账号
System.out.println("欢迎光临模拟银行");
Scanner scan = new Scanner(System.in);
int count=0;//记录输入错误的次数
while(1==1){//循环
System.out.println("请输入账号");
String zhm=scan.next();
System.out.println("请输入密码");
String mm=scan.next();
if(zhm.equals(zh.getZh()) mm.equals(zh.getPassword())){//输入的信息与zh账户信息的密码和账号一致
while(1==1){
System.out.println("当前余额为:"+zh.getJe()+"元。请选择操作:1.存款;2.取款;3.退出(只能输入数字)");
String cz=scan.next();
switch (Integer.parseInt(cz)) {
case 1:
System.out.println("请输入存款金额(输入小数)");
double ckje=scan.nextDouble();
zh.ck(ckje);
System.out.println("实施存款:"+ckje+"元,当前余额为"+zh.getJe()+"元");
break;
case 2:
System.out.println("请输入取款金额(输入小数)");
double qkje=scan.nextDouble();
zh.qk(qkje);
System.out.println("实施取款:"+qkje+"元,当前余额为"+zh.getJe()+"元");
break;
case 3:
break;
default:
System.out.println("暂无此功能");//输入1或者2、3以外的操作
break;
}
if("3".equals(cz)){
break;
}
}
System.out.println("退出操作");
break;
}else{
if(count=3){
System.out.println("已输入错误三次,账号被锁");
break;//结束循环
}else{
System.out.println("账号或密码错误,请重新输入");
count++;//错误一次count+1
continue;//进入下次循环
}
}
}
}
}
Q5: java银行存取款代码问题,做得好我就追加悬赏
您好,
创建状态
使用new运算符创建一个线程后,该线程仅仅是一个空对象,系统没有分配资源,称该线程处于创建状态(new thread)
可运行状态
使用start()方法启动一个线程后,系统为该线程分配了除CPU外的所需资源,使该线程处于可运行状态(Runnable)
运行中状态
Java运行系统通过调度选中一个Runnable的线程,使其占有CPU并转为运行中状态(Running)。此时,系统真正执行线程的run()方法。
package pack.java.thread.atm;
/**
* 账户类;
* @author Administrator
*
*/
public class Account {
private String name; //用户名;
private int value; //账户余额;
/**
* 存入金额;
* @param monery
*/
public void putMonery(int monery){
this.value = this.value + monery;
}
/**
* 取出金额;
* @param monery
* @return 金额;
*/
public int getMonery(int monery){
//判断是否账户余额是否大于 要取出的钱;
if(this.value monery ){
this.value = this.value - monery;
}else{
monery = this.value; //账户余额不够时,则取出,所有的账户余额的金额.
this.value = 0;
}
//返回取出的钱;
return monery;
}
/**
* 查询余额;
* @return 返回账户余额;
*/
public int search(){
return this.value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
关于java银行取钱代码和java编程银行存取款程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







