customerio.java

来自「本程序用Java语言描述了一个基本的银行管理系统」· Java 代码 · 共 34 行

JAVA
34
字号
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 + =
减小字号Ctrl + -
显示快捷键?