成都创新互联网站制作重庆分公司

java模拟用户汇款代码,java模拟用户汇款代码是什么

用JAVA语言编写程序,模拟银行账户功能。要有: 属性:账号、储户姓名、地址、存款余额、最小余额。

package com.cshr.test;

10年积累的网站制作、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有潜山免费网站建设让你可以放心的选择与我们合作。

public class bank {

private String card;//账号

private String uname;//储户姓名

private String address;//地址

private double money;//存款余额

public static final double minMoney=0;//最小余额

public bank(){}

public String getCard() {

return card;

}

public void setCard(String card) {

this.card = card;

}

public String getUname() {

return uname;

}

public void setUname(String uname) {

this.uname = uname;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public double getMoney() {

return money;

}

public void setMoney(double money) {

this.money = money;

}

public static double getMinmoney() {

return minMoney;

}

}

package com.cshr.test;

import java.util.List;

import org.hibernate.Session;

import com.utils.HibernateSessionFactory;

public class bankDao {

//存款

public void addMoney(double money,double Sqlmoney,String card){

Session session=HibernateSessionFactory.getSession();

try{

session.beginTransaction();

String hql="update bank b set b.money+="+money+Sqlmoney+" where b.card='"+card+"'";

session.createQuery(hql).executeUpdate();

session.beginTransaction().commit();

}catch(Exception e){

e.printStackTrace();

session.beginTransaction().rollback();

}finally{

HibernateSessionFactory.closeSession();

}

}

//取款

public void delMoney(double money,double Sqlmoney,String card){

Session session=HibernateSessionFactory.getSession();

try{

session.beginTransaction();

String hql="update bank b set b.money+="+(Sqlmoney-money)+" where b.card='"+card+"'";

session.createQuery(hql).executeUpdate();

session.beginTransaction().commit();

}catch(Exception e){

e.printStackTrace();

System.out.println("取款失败");

session.beginTransaction().rollback();

}finally{

HibernateSessionFactory.closeSession();

}

}

//查询所有

public Listbank selectfind(){

Session session=HibernateSessionFactory.getSession();

session.beginTransaction();

String hql="select b from bank b ";

Listbank list=session.createQuery(hql).list();

return list;

}

}

java需要写一个JAVA程序,模拟银行账户的查询、转账功能。

“\ T”选项卡,当输出数据显示,几乎以表格形式显示,目的是为了使数据看起来整齐点。

“\ n”换行,其他行显示下一个(...),目的是换行字符或字符串,使用System.out.println();效果是一样的。

求助[编写java程序]

首先先考虑需要设计哪几个类。

顾客这个类是必须的,还有计算银行的帐户还有多少钱的类。

最好,考虑的清楚一些,将不同的事件都分成类,因为java都是

由类组成的。刚初学的时候要多写多考虑哦,这样进步会很大的。

public class bank extends Thread{

public bank()

{

}

public static void main(String args[]) throws Exception

{

guest guest1 = new guest("guest1");

guest guest2 = new guest("guest2");

for(int i = 0; i 3; i++)

{

guest1.set_money();

sleep(2000);

guest1.get_money();

sleep(2000);

guest2.set_money();

sleep(2000);

guest2.get_money();

sleep(2000);

}

}

}

public class guest{

private String name;

private double sum_money = 0.0;

public guest(String name)

{

this.name = name;

}

public void get_name()

{

System.out.println(name);

}

public void set_name(String name)

{

this.name = name;

}

public void get_money()

{

System.out.println("目前"+ name + "有余额" + sum_money + "元");

}

public void set_money()

{

sum_money = sum_money + 100;

System.out.println(name + "存了100元");

}

}

首先编译guest类,再编译bank类。

有什么问题再问哦。

实现A B两个用户之间的转账,我的代码不正确,求修正java语言

1. 首先为什么线程启动2次

a.start();

b.start();

2.其次System.out.println("请输入您的选择:A转账到B或者B转账到A");

这个输入的值你那里有取得

JAVA编写银行账户程序摸拟银行账户的存\取款操作

public class ATM {

public static void main(String[] args) {

// 开立帐号

Account account = new Account();

// 在 account 中存 10,000 元

account.setBalance(10000);

// 检查 account 中的存款

System.out.println("帐户原始金额 : " + account.getBalance() + " 元");

// 小明, 小华与小英一起对 account 进行提款的动作

WithDraw s1 = new WithDraw("小明", account, 5000); // 小明 在 account 中提 5000 元

WithDraw s2 = new WithDraw("小华", account, 2000); // 小华 在 account 中提 2000 元

WithDraw s3 = new WithDraw("小英", account, 4000); // 小英 在 account 中提 4000 元

s1.start();

s2.start();

s3.start();

}

}

//帐户

class Account {

private int balance; // 帐户馀额

public int getBalance() { // 取得帐户馀额

return balance;

}

public void setBalance(int money) { // 设定帐户馀额

balance = money;

}

// 提款方法

public void withDraw(Account account, int withdrawMoney) {

String tName = Thread.currentThread().getName(); // tName=提款人

System.out.println(tName + " 开始提款 ... ");

boolean withDrawStatus; // 提款状态 说明:false=提款失败, true=提款成功

synchronized(ATM.class) {

int tmpBalabce = account.getBalance(); // 取得最新帐户馀额

//用 for-loop 模拟提款时系统所花的时间

for(double delay=0;delay99999999;delay++) {

// ... 提款进行中 ...

}

tmpBalabce = tmpBalabce - withdrawMoney; // 最新帐户馀额 - 欲提款金额 (用来判断是否馀额足够的依据)

if (tmpBalabce 0) { // 判断是否馀额足够

withDrawStatus = false;

System.out.println("....................");

System.out.println(" 帐户馀额不足!");

System.out.println("....................");

} else {

withDrawStatus = true;

account.setBalance(tmpBalabce); // 回存account最後剩馀金额

}

}

System.out.println(tName + "的交易单:");

System.out.println("\t欲提款金额:" + withdrawMoney + "元");

System.out.println("\t帐户馀额:" + account.getBalance());

if(withDrawStatus == true){

System.out.println(tName + " 完成提款 ... ");

} else {

System.out.println(tName + " 提款失败 ... ");

}

System.out.println("-------------------------------");

}

}

// 提款类别

class WithDraw extends Thread {

private Account account; // 帐号

private int withdrawMoney; // 欲提款的金额

// tName:执行绪名称, account:Account物件名称, withdrawMoney:欲提款金额

public WithDraw(String tName, Account account, int withdrawMoney) {

setName(tName);

this.account = account;

this.withdrawMoney= withdrawMoney;

}

public void run() {

// 执行提款动作(account:帐号, withdrawMoney 欲提款金额)

account.withDraw(account, withdrawMoney); // 执行提款动作

}

}

JAVA 编程创建Account 类模拟银行账户。

我帮你一共写了四个类,一个账户Account类,两个账户类的子类(信用卡账户CreditCardAccount类和借记卡DebitCardAccount类),另外再加上一个演示透支效果测试Test类。 代码贴在下面:

/**

* 账户类。

*

* @author CodingMouse

* @version 1.0

*/

public abstract class Account { protected String accountNumber; // 账号

protected double overage; // 余额

protected double annualInterestRate; // 年利率

/**

* 参数化构造器方法。

*

* 用于开户。

* @param accountNumber 预设账号

* @param overage 初始余额

* @param annualInterestRate 预设年利率

*/

public Account(String accountNumber, double overage, double annualInterestRate) {

super();

// 设定账号。

this.accountNumber = accountNumber;

// 设定初始余额,至少为零。

this.overage = overage = 0 ? overage : 0;

// 设定年利率,至少为零。

this.annualInterestRate = annualInterestRate = 0 ? annualInterestRate : 0;

}

/**

* 查询账号。

* @return 返回账号。

*/

public String getAccountNumber() {

return this.accountNumber;

}

/**

* 设置账号。

* @param accountNumber 新账号。

*/

public void setAccountNumber(String accountNumber) {

this.accountNumber = accountNumber;

} /**

* 查询余额方法。

* @return 返回账户余额。

*/

public double getOverage() {

return this.overage;

} /**

* 存款方法。

* @param money 要存入的金额。

* @return 返回true时存款成功,否则存款失败。

*/

public boolean depositMoney(double money) {

// 如果金额小于零,则不能存款

if (money = 0)

return false;

// 否则将相应的金额累加到账户余额中

this.overage += money;

return true;

}

/**

* 取款方法。

*

* 默认不能透支。

* @param money 要取出的金额。

* @return 返回true时取款成功,否则取款失败。

*/

public boolean drawMoney(double money) {

// 如果账户余额不足,则不能取款

if (this.overage money)

return false;

// 否则从账户余额中扣除相应的金额

this.overage -= money;

return true;

} /**

* 查询年利率。

* @return 返回年利率。

*/

public double getAnnualInterestRate() {

return this.annualInterestRate;

} /**

* 设置年利率。

* @param annualInterestRate 新的年利率。

*/

public void setAnnualInterestRate(double annualInterestRate) {

this.annualInterestRate = annualInterestRate;

}

}

--------------------------------------------------

/**

* 借记卡账户。

*

* 不能透支。

* @author CodingMouse

* @version 1.0

*/

public class DebitCardAccount extends Account { /**

* 重写父类构造器。

* @param accountNumber 预设账号

* @param overage 初始余额

* @param annualInterestRate 预设年利率

*/

public DebitCardAccount(String accountNumber, double overage,

double annualInterestRate) {

super(accountNumber, overage, annualInterestRate);

}}

-------------------------------------------------

/**

* 信用卡账户。

*

* 可以透支。

* @author CodingMouse

* @version 1.0

*/

public class CreditCardAccount extends Account { private double overdraftLimit; // 透支限度

/**

* 重载构造器。

*

* 便于构建可透支的信用卡账户实例。

* @param accountNumber 预设账号

* @param overage 初始余额

* @param annualInterestRate 预设年利率

* @param overdraftLimit 透支限度

*/

public CreditCardAccount(String accountNumber, double overage,

double annualInterestRate, double overdraftLimit) {

super(accountNumber, overage, annualInterestRate);

this.overdraftLimit = overdraftLimit;

} /**

* 查询透支限度的方法。

* @return 透支限度金额。

*/

public double getOverdraftLimit() {

return this.overdraftLimit;

} /**

* 设置透支限度的方法。

* @param overdraftLimit 新的透支限度金额。

*/

public void setOverdraftLimit(double overdraftLimit) {

// 透支限度必须为零和正数,否则为零。

this.overdraftLimit = overdraftLimit = 0 ? overdraftLimit : 0;

} /**

* 重写父类构造器。

* @param accountNumber 预设账号

* @param overage 初始余额

* @param annualInterestRate 预设年利率

*/

public CreditCardAccount(String accountNumber, double overage,

double annualInterestRate) {

super(accountNumber, overage, annualInterestRate);

} /**

* 重写父类取款方法。

*

* 将默认不能透支的取款改为可以透支的取款。

* @param money 要取出的金额。

* @return 返回true时取款成功,否则取款失败。

*/

@Override

public boolean drawMoney(double money) {

// 如果账户余额 + 透支限度的总金额仍不足,则不能取款

if (this.overage + this.overdraftLimit money)

return false;

// 否则从账户余额中扣除相应的金额

this.overage -= money;

return true;

}}

------------------------------------------

/**

* 测试账户使用。

*

* @author CodingMouse

* @version 1.0

*/

public class Test { /**

* 主程序方法。

* @param args 入口参数。

*/

public static void main(String[] args) {

// 创建一个不能透支的借记卡账户。

System.out.println("------------ 借记卡账户 ------------");

DebitCardAccount debitCardAccount = new DebitCardAccount("CHK20100117001", 100, 0.02);

// 初始余额有100元,调用并打印取90元和取120元的结果。

System.out.println("取90元的结果:" + debitCardAccount.drawMoney(90));

// 重新存入90元

debitCardAccount.depositMoney(90);

System.out.println("取120元的结果:" + debitCardAccount.drawMoney(120));

// 创建一个可以透支的信用卡账户。

System.out.println("------------ 信用卡账户 ------------");

CreditCardAccount crebitCardAccount = new CreditCardAccount("CHK20100117002", 100, 0.03, 50);

// 初始余额有100元,并且透支限度为50元,调用并打印取90元、取120元和取160元的结果。

System.out.println("取90元的结果:" + crebitCardAccount.drawMoney(90));

// 重新存入90元

crebitCardAccount.depositMoney(90);

System.out.println("取120元的结果:" + crebitCardAccount.drawMoney(120));

// 重新存入120元

crebitCardAccount.depositMoney(120);

System.out.println("取160元的结果:" + crebitCardAccount.drawMoney(160));

}

}

-------------------------------------- 在我机器上的测试打印结果为: ------------ 借记卡账户 ------------

取90元的结果:true

取120元的结果:false

------------ 信用卡账户 ------------

取90元的结果:true

取120元的结果:true

取160元的结果:false ----------------------------------------- 这个题目只是简单考查了下封装、继承、多态三大面向对象特性,我提供的代码仅作参考。 如果你懒得复制,想要程序源代码文件或有不明白的地方,可以发邮件到我QQ邮箱,我再回给你。


网页名称:java模拟用户汇款代码,java模拟用户汇款代码是什么
文章URL:http://cxhlcq.com/article/hcdeip.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部