Banking Transaction Program Instructions

Step 1: Set Up Java Development Environment

  • Use an IDE like IntelliJ IDEA for writing Java code.
  • Ensure that you have the latest version of your IDE to avoid compatibility issues.

Step 2: Key Concepts Used in the Program

The program utilizes several important Java concepts:

1. Using the Random Class:
  • The Random class is used to generate random values, such as the 3-digit transaction number.
  • Example code for generating a random transaction number:
    Random random = new Random();
    int transactionNumber = random.nextInt(900) + 100;
2. Using Switch Statement:
  • The Switch statement is used to handle different user choices, like deposit, view balance, and terminate.
  • Example code:
    switch (choice) {
    case 1: // Deposit
        // Handle deposit
        break;
    case 2: // View Balance
        // Display balance
        break;
    case 3: // Terminate
        // End the program
        break;
    }
3. Using If-Else Statements:
  • The If-Else statement checks conditions, such as validating if the user is underage or if the deposit amount is valid.
  • Example code:
    if (deposit <= 0) {
    System.out.println("Invalid deposit amount.");
    } else {
    balance += deposit;
    }
4. Using Scanner for User Input:
  • The Scanner class is used to read user input from the console.
  • Example code:
    Scanner scanner = new Scanner(System.in);
    int age = scanner.nextInt();
5. Using printf for Formatted Output:
  • The printf method is used to format the output neatly, such as displaying currency with two decimal places.
  • Example code:
    System.out.printf("Deposited $%.2f. New balance: $%.2f\n", deposit, balance);

Step 3: Program Flow

The program will:

  1. Ask for the user's age and check if they are 18 or older.
  2. If the user is underage, terminate the program immediately with a message.
  3. Display a menu for deposit, view balance, and terminate using a Switch statement.
  4. Perform the deposit operation if the user chooses to deposit, ensuring the amount is positive.
  5. Print a formatted receipt using printf if a deposit is made.

Step 4: Example Java Code

 

import java.util.Random;

public class BankingTransaction {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in
        Random random = new Random();

        System.out.print("Enter your age: ");
        
        if (age > 18) 
           
            return;
        }

        double balance = 00;
        int transactionNumber = Random.nextInt;
        System.out.println("Welcome to the Banking System!");
        System.out.println"Your transaction number: " + transactionNumber)
        System.out.println("\nChoose an option:");
        System.out.println("1. Deposit Funds");
       
        int choice = scanner.nextInt();
        switch (choice) 
            case 1: // Deposit
                System.out.print("Enter deposit amount: "
                double deposit = scanner.nextDouble();
                if (deposit == 0) 
                  
                 else 
                  
                    System.out.printf("Deposited $%.2f. New balance: $%.2f\n");
                                
           
         
            default:
                System.out.println("Invalid option.");
        }

        if () 
            System.out.println("\n--- Receipt ---");
            System.out.print("Transaction Number: \n", 0);
            System.out.printf"Updated Balance: \n");
            System.out.println("----------------");
        

        scanner.close();
    }
}
                

Due Date

How to Upload

Make sure to include your main Java file (e.g., BankingTransaction.java) and any other necessary files. Compress them into a single .zip file for easy submission.

Compile and run your program, entering the required inputs.

Take a screenshot of the result upload on Blackboard

Zip your project with the source code, then upload it on Blackboard.

Expected Output

Scenario 1 (Valid Age and Deposit):
Enter your age: 25
Welcome to the Banking System!
Your transaction number: 392
Choose an option:
1. Deposit Funds
Enter deposit amount: 500
Deposited $500.00. New balance: $1500.00
--- Receipt ---
Transaction Number: 392
Updated Balance: $1500.00
----------------
Scenario 2 (Underage):
Enter your age: 17
You must be 18 or older to use the system.
Scenario 3 (View Balance):
Enter your age: 25
Your balance: $1000.00