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+" 卡上余额不足,取款失败!"+" " + "操作时间:"+this.getAccounTimet()+" " );
return;
}
this._balance = this._balance - amount;
System.out.println("成功取款:"+amount);
checkAccount();
}
public void checkAccount(){
System.out.println("账户:"+this._account+" 卡上余额为:"+_balance+" " + "操作时间:"+this.getAccounTimet()+" " );
}
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);
}
}