1 public class Account { 2 3 private double balance; 4 5 public Account(double balance) 6 { 7 this.balance=balance; 8 } 9 public double getBalance() { 10 System.out.println("当前余额为:"+balance+"元"); 11 return balance; 12 } 13 public double deposit(double add){ 14 balance+=add; 15 System.out.println("存钱"+add+"元,当余额为"+balance+"元"); 16 return balance; 17 } 18 boolean withdraw(double get){ 19 if(get<=balance) 20 { 21 System.out.println("取钱"+get+"元,当余额为"+balance+"元"); 22 return true; 23 } 24 else 25 { 26 System.out.println("‘余额不足"); 27 return false; 28 } 29 }
时间: 2024-10-23 15:13:38