小项目--bank1
package banking1;
public class Account {
private double balance;//賬號余額
public Account(double init_balance){
balance=init_balance;
}
public double getBalance(){
return balance;
}
public void despoit(double amt){
balance+=amt;
}
public void withdraw(double amt){
if(balance>amt){
balance-=amt;
}else{
System.out.println("賬戶余額不足");
}
}
}
?
?
?
?
?
package testbanking1;
import banking1.Account;
public class testbanking1 {
public static void main(String[] args){
Account account;
account =new Account(500.00);
System.out.println("creating an account with a 500.00 balance ");
account.withdraw(150.00);//調用withdraw
System.out.println("withdraw 150.00");
account.despoit(22.50);
System.out.println("despoit 150.00");
account.withdraw(47.62);
System.out.println("withdraw 47.62");
System.out.println("the account has a balance of :"+account.getBalance());
}
}
轉載于:https://www.cnblogs.com/alhh/p/5342525.html
總結
以上是生活随笔為你收集整理的小项目--bank1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习进度表第五周
- 下一篇: Jquery 概念性内容编辑器