java编程题,银行方面的,求高手给个代码 。这个应该是多线程同步的问题,多个人取钱 , 要保证下一个线程拿到的值是正确的 。。。
Java模拟银行ATM完成以下功能: 1)查询余额 2)取款 3)存款 4)退出import java.util.Scanner;
public class ATM{
public static void main(String... args){
Scanner sc=new Scanner(System.in);
double money=0;
do{
System.out.println("请选择业务:1)查询余额 2)取款 3)存款 4)退出");
int c=sc.nextInt();
if(c==1){
System.out.println("用户余额为:"+money+"元");
}else if(c==2){
while(true){
System.out.println("请输入取款金额:");
double load=sc.nextDouble();
if(load=money){
System.out.println("账户余额不足,请重新输入取款金额");
continue;
}else{
money-=load;
System.out.println("取款成功");
break;
}
}
}else if(c==3){
System.out.println("请输入存款金额:");
money+=sc.nextDouble();
System.out.println("存款成功");
}else if(c==4){
System.exit(0);
}else{
System.out.println("输入错误,请重新选择业务");
}
}while(true);
}
}
翻译用JAVA程序模拟张三和李四在银行开户,存款,取款的过程,最后显示每一账户的存款的小程序以前写过一个小程序,没有开户过程 , 初始录入一个账户 。有存款,取款,查看交易详情 。
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
public class Bank {
private Customer customer = new Customer();
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public class Customer{
private String name;
private String address;
private String phoneNo;
private String accountNo;
private BigDecimal blance = new BigDecimal(0L);
private ListTransaction txnList = new ArrayListTransaction();// Transaction detail
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhoneNo() {
【银行取钱java代码 java编写银行取款系统】return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getAccountNo() {
return accountNo;
}
public void setAccountNo(String accountNo) {
this.accountNo = accountNo;
}
public BigDecimal getBlance() {
return blance;
}
public void setBlance(BigDecimal blance) {
this.blance = blance;
}
public ListTransaction getTxnList() {
return txnList;
}
public void setTxnList(ListTransaction txnList) {
this.txnList = txnList;
}
@Override
public String toString() {
return "Customer [name=" + name + ", address=" + address
+ ", phoneNo=" + phoneNo + ", accountNo=" + accountNo
+ ", blance=" + blance.doubleValue() + ", txnList=" + txnList + "]";
}
public void addTransaction(String type, double amount){
Transaction txn = new Transaction(type, amount);
this.txnList.add(txn);
}
public void depositing( double amount ){
System.out.println("depositing start");
this.blance = this.blance.add(new BigDecimal(amount));
this.addTransaction("1", amount);
System.out.println("depositing end success");
}
public void withdrawing( double amount ){
System.out.println("withdrawing start");
推荐阅读
- 推荐款单机游戏,推荐款单机游戏排行榜
- 如何有效营销基金,如何进行有效的游戏营销
- 苹果单机游戏助手,苹果 游戏助手
- python要懂函数吗 学python要背函数吗
- 便捷下载,便捷下载
- jquery中下列写法正确的是,下列关于jquery的描述错误的是
- jquery取消键盘模拟,js模拟键盘按下
- php168修改数据库 php修改数据表内容
- 3ds玩psp模拟器安卓版,3ds用最新ps模拟器