Module 6: Capstone Project

Building a Simple Console-Based Banking Application.

Putting It All Together

Welcome to the final module! The best way to solidify your knowledge is to build something real. In this capstone project, you will apply every concept you've learned—from variables and loops to classes and collections—to build a functional, interactive console application. This project will not only test your skills but also give you a tangible piece of software for your portfolio to show what you've accomplished.


1Project: Simple Banking Application

We are going to build a program that simulates the basic functions of a bank. It will run in the console and allow a user to interact with it by typing commands.

Core Features:

  • Create a new bank account with an account number and initial deposit.
  • Deposit money into an existing account.
  • Withdraw money from an existing account (with checks for insufficient funds).
  • Check the balance of an account.
  • Display all created accounts.
  • Exit the application.

Concepts We'll Use:

OOP: An `Account` class to blueprint what a bank account is.
Encapsulation: Private fields for account details, accessed via public methods.
Data Structures: An `ArrayList` to hold all the bank accounts.
User Input: The `Scanner` class to read commands from the user.
Control Flow: A `while` loop to keep the program running and a `switch` statement to handle the main menu.


2Step 1: Creating the `Account` Blueprint

First, we need to define what an `Account` is. Create a new class called `Account.java`. It will have private fields for the account number and balance, and public methods to interact with them.

public class Account {
    private String accountNumber;
    private double balance;
    
    public Account(String accountNumber, double initialDeposit) {
        this.accountNumber = accountNumber;
        this.balance = initialDeposit;
    }

    public String getAccountNumber() { return accountNumber; }
    public double getBalance() { return balance; }
    
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            System.out.println("Deposit successful. New balance: " + balance);
        }
    }
    
    public void withdraw(double amount) {
        if (amount > 0 && amount <= balance) {
            balance -= amount;
            System.out.println("Withdrawal successful. New balance: " + balance);
        } else {
            System.out.println("Withdrawal failed. Insufficient funds.");
        }
    }
}

3Step 2: Building the Main Application

Now, in your `Main.java` file, we'll write the logic to manage the application flow, display a menu, and handle user input.

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        ArrayList<Account> accounts = new ArrayList<>();
        boolean running = true;
        
        while (running) {
            System.out.println("\n--- Banking Menu ---");
            System.out.println("1. Create Account");
            System.out.println("2. Deposit");
            System.out.println("3. Withdraw");
            System.out.println("4. Check Balance");
            System.out.println("5. Exit");
            System.out.print("Enter your choice: ");

            int choice = scanner.nextInt();
            
            switch (choice) {
                case 1:
                    // Logic to create an account
                    break;
                case 2:
                    // Logic to deposit
                    break;
                // ... other cases ...
                case 5:
                    running = false;
                    System.out.println("Thank you for using our bank!");
                    break;
                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        }
    }
}