⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bank.java

📁 本程序用Java语言描述了一个基本的银行管理系统
💻 JAVA
字号:
package banking.domain;


public class Bank {
	public final static int MAX_CAPACITY = 200;

	private static Bank bankInstance = new Bank();

	private Customer[] customer;

	private int numberOfCustomers;

	public static Bank getBank() {
		return Bank.bankInstance;
	}

	private Bank() {
		this.customer = new Customer[Bank.MAX_CAPACITY];
		this.numberOfCustomers = 0;
	}
	
	public void kickCustomer(int index){
		this.customer[index] = null;
		for (int i=index; i<this.numberOfCustomers-1; ++i)
			this.customer[i] = this.customer[i+1];
		this.customer[this.numberOfCustomers-1] = null;
		this.numberOfCustomers--;
		System.gc();
	}

	public boolean addCustomer(String f, String l) {
		if (this.numberOfCustomers!=Bank.MAX_CAPACITY){
			this.customer[this.numberOfCustomers++] = new Customer(f, l);
			return true;
		}
		return false;
	}
	
	public boolean addCustomer(Customer customer){
		if (this.numberOfCustomers!=Bank.MAX_CAPACITY){
			this.customer[this.numberOfCustomers++] = customer;
			return true;
		}
		return false;
	}
	
	public Customer[] getCustomers(){
		return this.customer;
	}

	public int getNumOfCustomers() {
		return this.numberOfCustomers;
	}

	public Customer getCustomer(int index) {
		if (index<0 || index>=Bank.MAX_CAPACITY)
			return null;
		return this.customer[index];
	}

	public void sortCustomers() {
		if (this.numberOfCustomers > 1) {
			for (int i = 0; i < this.numberOfCustomers; ++i) {
				boolean flag = true;
				for (int j = 0; j < this.numberOfCustomers - 1 - i; ++j) {
					if (this.customer[j].compareTo(this.customer[j + 1]) > 0) {
						Customer temp = this.customer[j];
						this.customer[j] = this.customer[j + 1];
						this.customer[j + 1] = temp;
						flag = false;
					}
				}
				if (flag)
					break;
			}
		}
	}

	public int searchCustomers(String f, String l) {
		for (int i = 0; i < this.numberOfCustomers; ++i){
			if (this.customer[i].getFirstName().equals(f)
					&& this.customer[i].getLastName().equals(l)) {
				/*NumberFormat currency_format = NumberFormat
						.getCurrencyInstance();
				Customer customer = this.customer[i];
				System.out.println();
				System.out.println("Customer: " + customer.getLastName() + ", "
						+ customer.getFirstName());

				for (int acct_idx = 0; acct_idx < customer.getNumOfAccounts(); acct_idx++) {
					Account account = customer.getAccount(acct_idx);
					String account_type = "";

					// Determine the account type
					if (account instanceof SavingsAccount) {
						account_type = "Savings Account";
					} else if (account instanceof CheckingAccount) {
						account_type = "Checking Account";
					} else {
						account_type = "Unknown Account Type";
					}

					// Print the current balance of the account
					System.out.println("    " + account_type
							+ ": current balance is "
							+ currency_format.format(account.getBalance()));
					break;
				}*/
				return i;
			}
		}
		return -1;
	}
	
	public static void main(String[] args){
		Bank bank = Bank.getBank();
		bank.addCustomer(new Customer("jay", "chou"));
		bank.addCustomer(new Customer("bay", "chou"));
		bank.addCustomer(new Customer("cay", "ahou"));
		bank.sortCustomers();
		for (int i=0; i<bank.getNumOfCustomers(); ++i)
			System.out.println(bank.getCustomer(i).getFirstName()+" "+bank.getCustomer(i).getLastName());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -