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

📄 creditaccount.java

📁 A bank system
💻 JAVA
字号:


import java.text.DecimalFormat;
import java.util.ArrayList;

public class CreditAccount extends Account {
	private static final long serialVersionUID = 1L;
	private double limitAmount;
	public static double creditLimit;
	public static int minCreditAge;
		
	/**
	 * The constructor has a responsible to initial value for all essential data when the object is created
	 */
	public CreditAccount() {
		this.setAccountNumber(0);
		this.setAccountBalance(0.00);
		this.setOpeningBalance(0.00);
		this.setStatus('O');
		this.setLimitAmount(0.00);
	}
	
	/**
	 * The constructor has a responsible to initial value for all essential data when the object is created
	 * @param accountNumber				: Account number of Account ID --> seven digit number	
	 * @param limitAmount				: Credit account can have negative value equal to the limit amount
	 * @param customerArrayListObject	: ArrayList of Customer class to keep the owner of this account
	 */
	public CreditAccount(	int accountNumber,
							double limitAmount,
							ArrayList<Customer> customerArrayListObject){
		this.setAccountNumber(accountNumber);
		this.setAccountBalance(0.00);
		this.setOpeningBalance(0.00);
		this.setLimitAmount(-limitAmount);
		this.setStatus('O');
		this.setAccountOwnerArrayList(customerArrayListObject);
	}
	
	public void deposit(int accountNumber,
						double depositAmount,
						ArrayList<Transaction> transactionArrayListObject){
		
		if(this.getAccountNumber() == accountNumber){
				double tempAccountBalance = this.getAccountBalance(); 
				tempAccountBalance = tempAccountBalance + depositAmount;
				this.setAccountBalance(tempAccountBalance);
				
				Transaction tObject = new Transaction();
				tObject.setAccountNumber(accountNumber);
				tObject.setTransactionType("DEPOSIT");
				tObject.setAmount(depositAmount);
				tObject.setBalance(tempAccountBalance);

				//Add transaction object to ArrayList of Transaction class
				transactionArrayListObject.add(tObject);
				this.getTransactionHistoryArrayList().add(tObject);
		}else{
			System.out.println("Error!!! Wrong account number");
		}
	}
	
	public void withdraw(int accountNumber,
								double withdrawAmount,
								ArrayList<Transaction> transactionArrayListObject){
		
		if(this.getAccountNumber() == accountNumber){
			Transaction tObject = new Transaction();
			if(checkAvailableBalance(withdrawAmount)){
			double tempAccountBalance = this.getAccountBalance(); 
			tempAccountBalance = tempAccountBalance - withdrawAmount;
			this.setAccountBalance(tempAccountBalance); 
			
			tObject.setAccountNumber(accountNumber);
			tObject.setTransactionType("WITHDRAW");
			tObject.setAmount(withdrawAmount);
			tObject.setBalance(tempAccountBalance);
			
			//Add transaction object to ArrayList of Transaction class
			transactionArrayListObject.add(tObject);
			this.getTransactionHistoryArrayList().add(tObject);
			}else{
				DecimalFormat decimalPattern = new DecimalFormat("0.00");
				System.out.println("ERROR WITHDRAW : Not enought funds! The balance for account "+this.getAccountNumber()+" is "+"$"+decimalPattern.format(this.getAccountBalance()));
			}
		}else{
			System.out.println("Error!!! Wrong account number");
		}
	}
	
	public void transaction(int accountNumber){
		DecimalFormat decimalPattern = new DecimalFormat("0.00");
		
		if(this.getAccountNumber() == accountNumber){
			System.out.println("Account number:		"+this.getAccountNumber());
			System.out.print("Account owners: 	");
			for(Customer c: this.getAccountOwnerArrayList()){
				System.out.print(c.getCustomerID());
				System.out.print(" ");
			}
			System.out.println("");
			
			System.out.printf("Opening balance:	");
			System.out.printf("$%-20.2f",this.getOpeningBalance());
			System.out.println();
			for(Transaction t:this.getTransactionHistoryArrayList())
			{
				System.out.printf(t.getTransactionType()+"  \t");
				System.out.printf("\t$%-20.2f\t$%-20.2f%n",t.getAmount(),t.getBalance());
			}
		}else{
			System.out.println("Error!!! Wrong account number");
		}
	}
	
	/**
	 * This method validate that there is enought amount to withdraw
	 * @param withdrawAmount : The amount that customer want to withdraw
	 * @return boolean
	 */
	public boolean checkAvailableBalance(double withdrawAmount){
		
		double tempBalance = this.getAccountBalance(); 
		tempBalance = tempBalance - withdrawAmount;
		if(tempBalance >= this.getLimitAmount()){
			return true;
		}
		return false;
	}
			
	public double getLimitAmount() {
		return limitAmount;
	}
	
	public void setLimitAmount(double limitAmount) {
		this.limitAmount = limitAmount;
	}
}

⌨️ 快捷键说明

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