?? accountio.java
字號:
package banking.io;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import banking.domain.Account;
import banking.domain.CheckingAccount;
import banking.domain.SavingsAccount;
public class AccountIO {
final static int TYPE_SAVINGS = 1;
final static int TYPE_CHECKING = 2;
public static void writeAccount(Account account, DataOutput output)
throws IOException {
if (account instanceof SavingsAccount) {
output.writeInt(AccountIO.TYPE_SAVINGS);
output.writeDouble(((SavingsAccount) account).getInterestRate());
} else if (account instanceof CheckingAccount) {
output.writeInt(AccountIO.TYPE_CHECKING);
output.writeDouble(((CheckingAccount) account)
.getOverdraftProtection());
}
output.writeDouble(account.getBalance());
}
public static Account readAccount(DataInput input) throws IOException {
int type = input.readInt();
if (type == AccountIO.TYPE_CHECKING) {
double overdraftProtection = input.readDouble();
double balance = input.readDouble();
return new CheckingAccount(balance, overdraftProtection);
} else if (type == AccountIO.TYPE_SAVINGS) {
double interestRate = input.readDouble();
double balance = input.readDouble();
return new SavingsAccount(balance, interestRate);
}
return null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -