0% found this document useful (0 votes)
5 views2 pages

BankingApp Java'

The document is a Java program for a simple banking application that allows users to check their balance, deposit money, withdraw money, and exit the application. It includes input validation to handle invalid entries and ensures that deposit and withdrawal amounts are non-negative and do not exceed the current balance. The program runs in a loop until the user chooses to exit.

Uploaded by

drisha.0236
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

BankingApp Java'

The document is a Java program for a simple banking application that allows users to check their balance, deposit money, withdraw money, and exit the application. It includes input validation to handle invalid entries and ensures that deposit and withdrawal amounts are non-negative and do not exceed the current balance. The program runs in a loop until the user chooses to exit.

Uploaded by

drisha.0236
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;

public class BankingApp {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double balance = 0.0;
int choice;

while (true) {
System.out.println("\n=== Banking Application Menu ===");
System.out.println("1. Check Balance");
System.out.println("2. Deposit Money");
System.out.println("3. Withdraw Money");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");

if (!scanner.hasNextInt()) {
System.out.println("Invalid input. Please enter a number between 1
and 4.");
scanner.next(); // Clear invalid input
continue;
}

choice = scanner.nextInt();

switch (choice) {
case 1:
System.out.printf("Your current balance is: $%.2f\n", balance);
break;

case 2:
System.out.print("Enter amount to deposit: $");
double depositAmount = scanner.nextDouble();

if (depositAmount < 0) {
System.out.println("Deposit amount cannot be negative.");
} else {
balance += depositAmount;
System.out.printf("$%.2f deposited successfully. New
balance: $%.2f\n", depositAmount, balance);
}
break;

case 3:
System.out.print("Enter the amount to withdraw: $");
double withdrawAmount = scanner.nextDouble();

if (withdrawAmount < 0) {
System.out.println("Withdrawal amount cannot be
negative.");
} else if (withdrawAmount > balance) {
System.out.println("Insufficient balance.");
} else {
balance -= withdrawAmount;
System.out.printf("$%.2f withdrawn successfully. New
balance: $%.2f\n", withdrawAmount, balance);
}
break;
case 4:
System.out.println("Thank you for using our banking
application. Goodbye!");
scanner.close();
return; // exit the program

default:
System.out.println("Invalid choice. Please select a number
between 1 and 4.");
}
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy