⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 account.java

📁 银行账户管理系统 简称BAM(项目介绍及源码)
💻 JAVA
字号:
package model;

/**
 *	账户类(Account)
 *	作者:DrMeng 		日期:08/07/26   
 */
import java.io.*;
import exception.BussinessException;

public abstract class Account implements java.io.Serializable, Cloneable {
	private long id;// id:账户号码 长整数
	private String password;// password:账户密码
	private String name;// name:真实姓名
	private String personId;// personId:身份证号码 字符串类型
	private String email;// email:客户的电子邮箱
	private double balance;// balance:账户余额

	// 无参构造方法
	public Account() {
	}

	// 有参构造方法
	public Account(String password, String name, String personId, String email,
			double balance) {
		super();
		this.id = getNextId();// 自动账号生成
		this.password = password;
		this.name = name;
		this.personId = personId;
		this.email = email;
		this.balance = balance;
	}

	/**
	 * 方法: deposit: 存款方法,参数是double型的金额 withdraw:取款方法,参数是double型的金额
	 */
	// 存款的过程所有帐户都是一致的,所以放在父类
	public final void deposit(double money) {// 存款方法 存款方法改为不允许子类修改
		this.balance += money;
		System.out
				.println("========================<<存款>>成功!!========================");
		System.out.println("<<存款>>成功!!======>>" + "账户ID:" + this.id + "\t姓名:"
				+ this.name + "\t上次余额:" + (this.balance - money) + "\t存入:"
				+ money + "\t当前总金额:" + this.balance);
	}

	// //留给子类覆盖
	public abstract void withdraw(double money) throws BussinessException;// 取款方法
	// 取款方法根据不同的子类而不同,因此,改为抽象方法,在两个子类中分别实现

	// 获得下一个可分配的id
	private synchronized long getNextId() {
		FindFile find = new FindFile();// 判断文件是否存在

		long id = 0;
		try {
			FileInputStream fi = new FileInputStream(find.getIdFilePath());
			DataInputStream in = new DataInputStream(fi);
			id = in.readLong();
			in.close();
		} catch (FileNotFoundException e) {
			// id=100001;
		} catch (IOException e) {
			e.printStackTrace();
		}

		DataOutputStream out = null;
		try {
			FileOutputStream fo = new FileOutputStream(find.getIdFilePath());
			out = new DataOutputStream(fo);
			out.writeLong(id + 1);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (out != null)
					out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		return id;
	}

	/**
	 * 
	 * @Get/Set方法
	 */
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPersonId() {
		return personId;
	}

	public void setPersonId(String personId) {
		this.personId = personId;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public double getBalance() {
		return balance;
	}

	public void setBalance(double balance) {
		this.balance = balance;
	}

	// 方法重写
	@Override
	public String toString() {
		return "账户卡号: " + id+"\t\t姓名:"+name;
	}

	@Override
	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (o == null)
			return false;
		if (this.getClass() != o.getClass())
			return false;
		Account c = (Account) o;
		if (c.id == this.id && c.balance == this.balance)
			return true;
		else
			return false;
	}

	@Override
	// 对象复制要实现Cloneable接口,对象序列化要实现java.io.Serializable接口
	public Object clone() {
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
			return null;
		}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -