📄 account.java
字号:
package tarena.bank.server;
import java.io.*;
public class Account implements Serializable{
public int type;
private long id;
private String passwd;
private String name;
private String personId;
private String email;
private double balance;
public Account(){
}
public Account(long id,String passwd, String name, String personId, String email,double balance,int type) {
this.id=id;
this.passwd = passwd;
this.name = name;
this.personId = personId;
this.email = email;
this.balance=balance;
this.type=type;
}
public synchronized static long CreatId(){
Account account=null;
try {
FileInputStream infile = new FileInputStream(
"C:\\Documents and Settings\\Administrator\\桌面\\id.list");
ObjectInputStream ois = new ObjectInputStream(infile);
account = (Account)(ois.readObject());
FileOutputStream outfile = new FileOutputStream(
"C:\\Documents and Settings\\Administrator\\桌面\\id.list");
ObjectOutputStream oos = new ObjectOutputStream(outfile);
Account a = new Account();
a.setId(account.id+1);
oos.writeObject(a);
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return account.id;
}
public long getId() {
return id;
}
double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
String getPasswd() {
return passwd;
}
void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getPersonId() {
return personId;
}
public void setPersonId(String personId) {
this.personId = personId;
}
public synchronized void withdraw(double money){
if(money<=0){
System.out.println("Operation Canceled!");
}
else if(money>balance){
System.out.println("The money you get is beyond your balance!");
}
else{
this.balance=this.balance-money;
}
}
public final void deposit(double money) {
this.balance = this.balance + money;
}
public void setId(long id) {
this.id = id;
}
public String toString(){
return id+"\t"+passwd+"\t"+name+"\t"+personId+"\t"+email+"\t"+this.getBalance()+"\t"+this.type;
}
public boolean equals(Object o){
return this.id==((Account)o).id;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -