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

帐户管理

时间:2018-05-01 20:29:51      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:imp   结果   his   format   账户   成功   0.00   simple   时间   

package 账户管理;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Zhanghu {
     private String _account;
     private String _name;
     private String _ID;
     private Date _accounTimet ;
     private double _balance;
    
     public Zhanghu(String account , String name , String ID , double balance ){
         this._account = account;
         this._name = name;
         this._ID = ID;
         this._accounTimet = new Date();
         this._balance = balance;
     }
    
     //存款
     public void deposit(double amount){
        
         _balance +=amount;
         System.out.println("成功存款:"+amount);
         checkAccount();
     }
    
     //取款
     public void withDrawal(double amount){
         if(amount > _balance){
             System.out.println("账户:"+this._account+" 卡上余额不足,取款失败!"+"\n" +  "操作时间:"+this.getAccounTimet()+"\n" );
             return;
         }
         this._balance = this._balance - amount;
         System.out.println("成功取款:"+amount);
         checkAccount();
        
     }
     public void checkAccount(){
         System.out.println("账户:"+this._account+" 卡上余额为:"+_balance+"\n"  +  "操作时间:"+this.getAccounTimet()+"\n" );
     }
    
    
     public String getID() {
         return _ID;
     }
     public void setID(String iD) {
         _ID = iD;
     }
     public String getAccount() {
         return _account;
     }
     public void setAccount(String account) {
         this._account = account;
     }
     public String getName() {
         return _name;
     }
     public void setName(String name) {
         this._name = name;
     }
     public String getAccounTimet() {
        
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
        
         return sdf.format(this._accounTimet);
     }
     public void setAccounTimet(Date accounTimet) {
         this._accounTimet = accounTimet;
     }
     public double getBalance() {
         return _balance;
     }
     public void setBalance(double balance) {
         this._balance = balance;
     }
    
 }

 

package 账户管理;

public class Zhumain {
public static void main(String[] args){
       
 Zhanghu account =  new Zhanghu("123456", "张三","000001",500.00);
        account.checkAccount();
        account.deposit(100.00);
        account.withDrawal(400.00);
    }
     }

结果为:

账户:123456 卡上余额为:500.0
操作时间:2018:05:01 16:33:23

成功存款:100.0
账户:123456 卡上余额为:600.0
操作时间:2018:05:01 16:33:23

成功取款:400.0
账户:123456 卡上余额为:200.0
操作时间:2018:05:01 16:33:23

帐户管理

标签:imp   结果   his   format   账户   成功   0.00   simple   时间   

原文地址:https://www.cnblogs.com/maxue/p/8976625.html

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