Java bank - Abstract class

Modify the existing account class to an abstract class, and modify the normal account and the minus account to inherit the abstract account class. If you need a new kind of account class, then this class will inherit the abstract account class.

Let's create a custom exception class to use when there is insufficient amounts at the time of withdrawal.
Create and save InsufficientBalanceException class to inherit RuntimeException as shown below.
Custom Exception 1
Right-click on an empty space in the Eclipse editor view to display the context menu.
Select Source and Generate Constructors form SuperClass ... to create the constructor.
Custom Exception 2

InsufficientBalanceException.java
package net.java_school.bank;

public class InsufficientBalanceException extends RuntimeException {

	private static final long serialVersionUID = -8617159875648641557L;

	public InsufficientBalanceException() {
		super();
	}

	public InsufficientBalanceException(String message, Throwable cause) {
		super(message, cause);
	}

	public InsufficientBalanceException(String message) {
		super(message);
	}

	public InsufficientBalanceException(Throwable cause) {
		super(cause);
	}

}

Create an exception class to use when registering an account with an existing account number in the same way as above.

DuplicateAccountException.java
package net.java_school.bank;

public class DuplicateAccountException extends RuntimeException {

	private static final long serialVersionUID = -100648724423914991L;

	public DuplicateAccountException() {
		super();
	}

	public DuplicateAccountException(String message, Throwable cause) {
		super(message, cause);
	}

	public DuplicateAccountException(String message) {
		super(message);
	}

	public DuplicateAccountException(Throwable cause) {
		super(cause);
	}

}

Change the existing account class to an abstract class. Change the withdraw() method to an abstract method.

Account.java
public abstract class Account {

	//.. Same as existing code ..
		
	public abstract void withdraw(long amount);
	
	//.. Same as existing code .. 
}

Generate a normal account that can not be withdrawn larger than the balance.

NormalAccount.java
package net.java_school.bank;

import java.util.Calendar;
import java.util.Date;

public class NormalAccount extends Account {

	public NormalAccount() {}
	
	public NormalAccount(String accountNo, String name, String kind) {
		super(accountNo, name, kind);
	}

	public NormalAccount(String accountNo, String name, long balance, String kind) {
		super(accountNo, name, balance, kind);
	}
	
	@Override
	public void withdraw(long amount)  {
		if (amount > balance) {
			throw new InsufficientBalanceException("There is not enough balance.");
		}
		balance = balance - amount;
		Transaction transaction = new Transaction();
		Calendar cal = Calendar.getInstance();
		Date date = cal.getTime();
		transaction.setTransactionDate(Account.DATE_FORMAT.format(date));
		transaction.setTransactionTime(Account.TIME_FORMAT.format(date));
		transaction.setAmount(amount);
		transaction.setKind(Account.WITHDRAW);
		transaction.setBalance(this.balance);
		transactions.add(transaction);
	}
	
}
Bank.java
package net.java_school.bank;

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

public class Bank {
	private ArrayList<Account> accounts = new ArrayList<Account>();

	public void addAccount(String accountNo, String name, String kind) {
		Account account = getAccount(accountNo);
		if (account != null) throw new DuplicateAccountException("Duplicated account.");
		
		if (Account.NORMAL.equals(kind)) {
			accounts.add(new NormalAccount(accountNo, name, kind));
		} else if (Account.MINUS.equals(kind)) {
			accounts.add(new MinusAccount(accountNo, name, kind));
		}
	}
	
	public void addAccount(String accountNo, String name, long balance, String kind) {
		Account account = getAccount(accountNo);
		if (account != null) throw new DuplicateAccountException("Duplicated account.");
		
		if (Account.NORMAL.equals(kind)) {
			accounts.add(new NormalAccount(accountNo, name, balance, kind));
		} else if (Account.MINUS.equals(kind)) {
			accounts.add(new MinusAccount(accountNo, name, balance, kind));
		}
	}
	
	//.. Omitted ..  
	
}