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

📄 bank.java

📁 通过图形用户界面输入一句话
💻 JAVA
字号:
/**
 * 
 */
package com.hp.gdcc.training.homework39;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yanshuo
 * 
 */
public class Bank {
	/**
	 * 当前账户数量
	 */
	long amount = 0;

	/**
	 * 当前所有的账户对象的集合
	 */
	List<Account> accountList;

	// /**
	// * 当前所有的账户对象的集合
	// */
	// Map<Long, Account> accountMap;

	public Bank() {
		this.accountList = new ArrayList<Account>();
		// this.accountMap = new HashMap<Long, Account>();
	}

	public long getAmount() {
		return amount;
	}

	public List<Account> getAccountList() {
		return accountList;
	}

	/**
	 * 用户开户
	 * 
	 * @param id
	 * @param password
	 * @param passwordAffirm
	 * @param name
	 * @param personId
	 * @param email
	 * @param accountType
	 * @return Account
	 */
	public Account openAccount(long id, String password, String passwordAffirm,
			String name, String personId, String email, int accountType) {
		Account account = null;
		if (password != null && password.equals(passwordAffirm)) {
			if (accountType == 0) {
				account = new SavingAccount(id, password, name, personId,
						email, accountType);
			} else if (accountType == 1) {
				account = new CreditAccount(id, password, name, personId,
						email, accountType);
			}
		} else {
			System.out.println("开户失败");
			return account;
		}

		this.amount++;
		this.accountList.add(account);
		// this.accountMap.put(id, account);
		System.out.println("开户成功");
		return account;
	}

	/**
	 * 设定透支额度
	 * 
	 * @param id
	 * @param ceiling
	 * @return Account
	 */
	public Account setOverdraft(long id, double ceiling) {
		 Account tempAccount = null;
		for (int i = 0; i < this.accountList.size(); i++) {
			
			tempAccount = this.accountList.get(i);
			if (tempAccount.getId() == id) {
				CreditAccount creditAccount = (CreditAccount) tempAccount;
				creditAccount.setCeiling(ceiling);
				break;
				// 思考一下为什么这个地方不需要this.accountList.set(tempAccount);
			}
		}
		return tempAccount;
	}

	/**
	 * 统计银行所有账户余额总数
	 * 
	 * @return double
	 */
	public double getAllAccountBalance() {
		double allAccountBalance = 0;
		for (int i = 0; i < this.accountList.size(); i++) {
			Account tempAccount = accountList.get(i);
			allAccountBalance += tempAccount.getBalance();
		}
		return allAccountBalance;
	}

	/**
	 * 统计所有信用帐户透支额度总数
	 * 
	 * @return double
	 */
	public double getAllCreditAccountBalance() {
		double allCreditAccountCeiling = 0;
		for (int i = 0; i < this.accountList.size(); i++) {
			Account tempAccount = accountList.get(i);
			int accountType = tempAccount.getAccountType();
			if (accountType == 1) {
				allCreditAccountCeiling += ((CreditAccount) tempAccount)
						.getCeiling();
			}
		}
		return allCreditAccountCeiling;
	}

	/**
	 * 用户登录
	 * 
	 * @param id
	 * @param password
	 * @return Account
	 */
	public Account login(long id, String password) {
		Account account = null;
		for (int i = 0; i < this.accountList.size(); i++) {
			Account tempAccount = accountList.get(i);
			if (tempAccount.getId() == id
					&& tempAccount.getPassword().equals(password)) {
				account = tempAccount;
				break;
			}
		}
		return account;
	}

	/**
	 * 存款
	 * 
	 * @param account
	 * @param depositAmount
	 * @return Account
	 */
	public Account deposit(Account account, double depositAmount) {
		boolean isDepositSuccess = account.deposit(depositAmount);
		if (isDepositSuccess) {
			System.out.println("存款成功");
		} else {
			System.out.println("存款无效");
		}
		return account;
	}

	/**
	 * 取款
	 * 
	 * @param account
	 * @param withdrawAmount
	 * @return Account
	 */
	public Account withdraw(Account account, double withdrawAmount) {
		boolean isWithdraw = account.withdraw(withdrawAmount);
		if (isWithdraw) {
			System.out.println("取款成功");
		} else {
			System.out.println("取款无效");
		}
		return account;
	}
}

⌨️ 快捷键说明

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