码迷,mamicode.com
首页 > 其他好文 > 详细

小项目--bank1

时间:2016-03-31 20:29:52      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/alhh/p/5342525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!