小项目--bank1
Posted ALHH
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小项目--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());
}
}
以上是关于小项目--bank1的主要内容,如果未能解决你的问题,请参考以下文章