The program utilizes several important Java concepts:
Random Class:Random class is used to generate random values, such as the 3-digit transaction number.Random random = new Random();
int transactionNumber = random.nextInt(900) + 100;
Switch Statement:Switch statement is used to handle different user choices, like deposit, view balance, and terminate.switch (choice) {
case 1: // Deposit
// Handle deposit
break;
case 2: // View Balance
// Display balance
break;
case 3: // Terminate
// End the program
break;
}
If-Else Statements:If-Else statement checks conditions, such as validating if the user is underage or if the deposit amount is valid.if (deposit <= 0) {
System.out.println("Invalid deposit amount.");
} else {
balance += deposit;
}
Scanner for User Input:Scanner class is used to read user input from the console.Scanner scanner = new Scanner(System.in);
int age = scanner.nextInt();
printf for Formatted Output:printf method is used to format the output neatly, such as displaying currency with two decimal places.System.out.printf("Deposited $%.2f. New balance: $%.2f\n", deposit, balance);
The program will:
Switch statement.printf if a deposit is made.
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();
}
}
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.
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
----------------
Enter your age: 17
You must be 18 or older to use the system.
Enter your age: 25
Your balance: $1000.00