?? account.java
字號:
package model;import Exception.*;import java.io.*;public abstract class Account implements Serializable, Cloneable { private long id; private String password; private String name; private String personId; private String email; private double balance; public Account() { } public Account(String password, String name, String personId, String email) { this(); this.id = getNextId(); this.password = password; this.name = name; this.personId = personId; this.email = email; } private static synchronized long getNextId() { /* * 從文件里讀取一個id值 */ DataInputStream in = null; long sid = 10000; try { // FileInputStream fin=new // FileInputStream("/home/soft01/workspace/mybam/Data/id.txt"); FileInputStream fin = new FileInputStream( "D:\\sh_workspace\\Bank\\Data\\id.txt"); in = new DataInputStream(fin); sid = in.readLong(); } catch (FileNotFoundException e) { } catch (IOException e) { } finally { try { if (in != null) in.close(); } catch (IOException e) { } } sid++; /* * 把新的id值寫回文件 */ DataOutputStream out = null; try { // FileOutputStream fou=new // FileOutputStream("/home/soft01/workspace/mybam/Data/id.txt"); FileOutputStream fou = new FileOutputStream( "D:\\sh_workspace\\Bank\\Data\\id.txt"); out = new DataOutputStream(fou); out.writeLong(sid); } catch (FileNotFoundException e) { } catch (IOException e) { } finally { try { if (out != null) out.close(); } catch (IOException e) { } } return sid; } public long getId() { return id; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public String getEmail() { return email; } public String getName() { return name; } public String getPassword() { return password; } public String getPersonId() { return personId; } /* * 為什么存款方法deposit()提供實現,而把取款方法withdraw()設計成抽象方法? */ public final synchronized void deposit(double money) { this.balance = this.balance + money; } public abstract void withdraw(double money) throws BusinessException.BalanceNotEnoughException; public String toString() { return this.getName() + "\t" + this.getPersonId() + "\t" + this.getEmail(); } /* * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object o) { if (this == o) return true; if (o == null) return false; if (this.getClass() != o.getClass()) return false; Account c = (Account) o; boolean flag = true; if (!(this.password.equals(c.password))) flag = false; else if (!(this.name.equals(c.name))) flag = false; else if (!(this.personId.equals(c.personId))) flag = false; else if (!(this.email.equals(c.email))) flag = false; else if (this.getBalance() != c.getBalance()) flag = false; return flag; } @Override public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); return null; } } @Override public int hashCode() { return new Long(id).hashCode()^password.hashCode()^name.hashCode() ^personId.hashCode()^email.hashCode()^new Double(balance).hashCode(); } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -