Java03
多线程业务
package day08;public class Account {private String cardId;//卡号private double money;//余额public Account() {}public Account(String cardId, double money) {this.cardId = cardId;this.money = money;}public String getCardId() {return cardId;}public void setCardId(String cardId) {this.cardId = cardId;}public double getMoney() {return money;}@Overridepublic String toString() {return "Account{" +"cardId='" + cardId + '\'' +", money=" + money +'}';}public void setMoney(double money) {this.money = money;}public void drawMoney(int money) {//先弄清楚到底是谁来取钱String name = Thread.currentThread().getName();if(this.money>=money){System.out.println(name + "来取钱" + money + "成功!");this.money=this.money-money;System.out.println(name + "来取钱后,余额剩余" + this.money);}else{System.out.println(name + "来取钱,余额不足~");}}
}
package day08;public class DrawThread extends Thread {private Account account;public DrawThread(){//无参构造器}public DrawThread(Account account,String name){super(name);//一定要放在上面this.account=account;}@Overridepublic void run() {//线程调用方法进行取钱account.drawMoney(100000);}}