- 银行账户类
package text;
//账户类Account
public class Account {
private String cid;
private double balance;
private Customer c;
//全参构造
public Account(String cid, double balance, Customer c) {
super();
this.cid = cid;
this.balance = balance;
this.c = c;
}
//无参构造
public Account() {
super();
}
//GetSet方法
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public Customer getC() {
return c;
}
public void setC(Customer c) {
this.c = c;
}
//Getinfo方法
public String getInfo() {
return "卡号" + cid +"\n余额" + balance +"\n银行账户" + c;
}
//取钱方法withdraw()
public boolean withdraw(double qu) {
if(qu<=balance) {
balance-=qu;
return true;
}
else{
return false;
}
}
public boolean save(double cun) {
if(cun>0) {
balance+=cun;
return true;
}
else {
return false;
}
}
}
2.用户信息类
package text;
// 用户信息类 Customer
public class Customer {
String name;
String id;
String dizhi;
String dianhua;
//GetSet方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDizhi() {
return dizhi;
}
public void setDizhi(String dizhi) {
this.dizhi = dizhi;
}
public String getDianhua() {
return dianhua;
}
public void setDianhua(String dianhua) {
this.dianhua = dianhua;
}
//
public String say() {
return "\n姓名:" +name+ "\n银行卡号:" +id+ "\n地址:" +dizhi+ "\n电话:" +dianhua;
}
}
3.测试类
package text;
//银行账户 Bank测试类
public class Bank {
public static void main(String[] args) {
Customer cus = new Customer();
Account a = new Account();
a.setCid("1234567");
a.setBalance(20000);
a.setC(cus);
cus.setName("宇神");
cus.setId("");
cus.setDianhua("13203997019");
cus.setDizhi("焦作");
a.withdraw(19000);
a.save(1000000);
a.getInfo();
cus.say();
System.out.println(a.getInfo());
System.out.println(cus.say());
}
}
有什么不好的地方请大家说出来