📄 customerio.java
字号:
package banking.io;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import banking.domain.Customer;
public class CustomerIO {
public static void writeCustomer(Customer customer, DataOutput output)
throws IOException {
output.writeInt(customer.getNumOfAccounts());
FixedLengthStringIO.writeFixedLengthString(customer.getFirstName(),
Customer.STRING_SIZE, output);
FixedLengthStringIO.writeFixedLengthString(customer.getLastName(),
Customer.STRING_SIZE, output);
for (int i = 0; i < customer.getNumOfAccounts(); ++i) {
AccountIO.writeAccount(customer.getAccount(i), output);
}
}
public static Customer readCustomer(DataInput input) throws IOException {
int numOfAccounts = input.readInt();
String firstName = FixedLengthStringIO.readFixedLengthString(
Customer.STRING_SIZE, input);
String lastName = FixedLengthStringIO.readFixedLengthString(
Customer.STRING_SIZE, input);
Customer customer = new Customer(firstName, lastName);
for (int i = 0; i < numOfAccounts; ++i)
customer.addAccount(AccountIO.readAccount(input));
return customer;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -