我就不分2个类了。下面贴出代码和结果。
public class Account{
String customerId;
String accountNo;
double balance;
public Account(String _customerId,String _accountNo,double _balance){ //构造方法1,
this.customerId=_customerId;
this.accountNo=_accountNo;
this.balance=_balance;
return;
}
public Account(String _customerId,String _accountNo){ //构造方法2
this.customerId=_customerId;
this.accountNo=_accountNo;
this.balance=0;
return;
}
public void setCustomerId(String _customerId){ //设置身份信息
this.customerId=_customerId;
}
public String getCustomerId(){ //获取身份信息
return this.customerId;
}
public void setAccountNo(String _accountNo){ //设置账号ID
this.accountNo=_accountNo;
}
public String getAccount(){ //获取账号信息
return this.accountNo;
}
public void setBalance(double _balance){ //设置初始存款
this.balance=_balance;
}
public double getBalance(){ //获取存款信息
return this.balance;
}
public double deposit(double savecash){ //存款
this.balance=savecash+this.balance;
return this.balance;
}
public double withdraw(double getcash){ //取款
this.balance=this.balance-getcash;
return this.balance;
}
public static void main(String [] args){
Account a1=new Account("张三","20155251",2000);
Account a2=new Account("张三","20155252");
Account a3=new Account("李四","20155253",3000);
a1.withdraw(500);
a1.withdraw(1000);
a2.deposit(1000);
a3.withdraw(300);
System.out.println(a1.getAccount());
System.out.println(a1.getBalance());
System.out.println(a2.getAccount());
System.out.println(a2.getBalance());
System.out.println(a3.getAccount());
System.out.println(a3.getBalance());
}
}
写这么多 LOOk my ID