创建一个账户Account类,该类有id:账户号码(字符串类型),password:账户密码(int),name:真实姓名(字符串类型),
personId:身份证号码(字符串类型),email:客户的电子邮箱(字符串类型),balance:账户余额(double)。
存款方法:deposit(double balance),取款方法:withdraw(double balance)。构造方法:有参和无参,有参构造方法用于设置必要的属性
并且通过test()方法将所有成员变量打印出来,调用存款和取款方法
package lianxi04;
import java.util.Date;
public class Account {
public String id;
public String password;
public String name;
public String personId;
public String email;
public double balance;
public Account(){
}
public Account( String password, String name, String personId, String email, double balance) {
super();
this.id = String.valueOf(new Date().getTime());
this.password = password;
this.name = name;
this.personId = personId;
this.email = email;
this.balance = balance;
}
public void cun(double money){
balance += money;
System.out.println("账户:"+id+"存了"+money+"元,当前余额为"+balance+"元");
}
public void qu(double money){
if(balance < money){
System.out.println("余额不足");
}else{
balance -= money;
System.out.println("账户:"+id+"取了"+money+"元,当前余额为"+balance+"元");
}
}
@Override
public String toString() {
return "Account [id=" + id + ", password=" + password + ", name=" + name + ", personId=" + personId + ", email="
+ email + ", balance=" + balance + "]";
}
}
package lianxi04;
public class Test {
public static void main(String[] args) {
Account a = new Account("000000", "张三", "123456", "111@qq.com", 10);
System.out.println(a.toString());
a.cun(100);
a.qu(50);
}
}