if (this.getBalance() >= money) {
this.setBalance(this.getBalance() - money); return this; } else {
if (this.getBalance() + this.getCeiling() >= money) {
System.out.println(\本次已透支\ this.setCeiling(this.getCeiling() + this.getBalance() - money); System.out.println(\可透支\ this.setBalance(0); return this; } else {
System.out.println(\余额不足,超过透支额度\ return null; } } }
@Override
public String toString() {
Double d = new Double(getBalance()); Double c = new Double(getCeiling());
return getId() + \ + string(getPersonId()) + string(getEmail())
+ string(d.toString()) + string(c.toString()) + string(\ + \ } }
4.1.3 储蓄账户模型 package ATM_Bank;
//储蓄账户
public class SavingAccount extends Account { public SavingAccount() {
}
public SavingAccount(Long id, String password, String name, String personId, String email, double balance) { // TODO 自动生成的构造函数存根 this.setId(id);
this.setPassword(password); this.setName(name);
this.setPersonId(personId); this.setEmail(email);
this.setBalance(balance); }
// 取款
protected Account withdraw(double money) { if (this.getBalance() >= money) {
this.setBalance(this.getBalance() - money); return this; } else {
System.out.println(\余额不足\ return null; } }
@Override
public String toString() {
Double d = new Double(getBalance());
return getId() + \ + string(getPersonId()) + string(getEmail())
+ string(d.toString()) + string(\ + \ } }
4.1.4 可以贷款可以透支账户模型 package ATM_Bank;
//可以贷款可以透支账户
public class LoanCreditAccount extends CreditAccount implements Loanable {
@Override
public Account requestLoan(double money) { // TODO 自动生成的方法存根 return null; }
@Override
public Account payLoan(double money) { // TODO 自动生成的方法存根 return null; }
public LoanCreditAccount(Long id, String password, String name,
String personId, String email, double balance, double ceiling, Long loanAmount) {
this.setId(id);
this.setPassword(password); this.setName(name);
this.setPersonId(personId); this.setEmail(email); this.setBalance(balance); this.setCeiling(ceiling);
this.setLoanAmount(loanAmount); }
@Override
public String toString() {
Double d = new Double(getBalance()); Double c = new Double(getCeiling());
return getId() + \ + string(getPersonId()) + string(getEmail()) + string(d.toString()) + string(c.toString())
+ string(getLoanAmount().toString()) + \ } }
4.1.5 可以贷款不可以透支账户模型 package ATM_Bank;
//可以贷款不可以透支账户
public class LoanSavingAccount extends SavingAccount implements Loanable {
@Override
public Account requestLoan(double money) { // TODO 自动生成的方法存根 return null; }
@Override
public Account payLoan(double money) { // TODO 自动生成的方法存根 return null; }
public LoanSavingAccount(Long id, String password, String name,
String personId, String email, double balance, Long loanAmount) { this.setId(id);
this.setPassword(password); this.setName(name);
this.setPersonId(personId);
}
this.setEmail(email); this.setBalance(balance);
this.setLoanAmount(loanAmount); }
@Override
public String toString() {
Double d = new Double(getBalance());
return getId() + \ + string(getPersonId()) + string(getEmail()) + string(d.toString()) + string(\
+ string(getLoanAmount().toString()) + \}
4.2 Bank类
package ATM_Bank; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Scanner;
public class Bank {
private ArrayList setAcc = new ArrayList(); // 当前所有的账户对象的信息
private int index = 0; // 当前账户数量
public int getIndex() { return index; }
public void setIndex(int index) { this.index = index; }
// 创建文件
public File creatFile() {
File file = new File(\
file = new File(\ try {
file.createNewFile(); } catch (IOException e) {
// TODO 自动生成的 catch 块 e.printStackTrace(); }
return file; }
// 写文件
public void writeFile(File file, String str) { OutputStream outputStream = null; try {
outputStream = new FileOutputStream(file); str = str.replace(\ str = str.replace(\
str = \账户号码 账户密码 身份证号码 客户的电子邮箱 账户余额 贷款金额 用户类型\\r\\n \
+ str.replace(\ byte[] b = str.getBytes(); outputStream.write(b);
} catch (FileNotFoundException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (IOException e) {
// TODO 自动生成的 catch 块 e.printStackTrace(); } finally { try {
outputStream.close(); } catch (IOException e) {
// TODO 自动生成的 catch 块 e.printStackTrace(); } } }
private Long getID() {
DateFormat ny = new SimpleDateFormat(\ String str = \
str += ny.format(new Date()) + \ Long Id = new Long(str);
真实姓名透支额度