Advertisement
LynchzDEV

Simple Bank

Jul 2nd, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SimpleBank {
  4.     private String accountNumber;
  5.     private double balance;
  6.  
  7.     public void createAccount() {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         System.out.print("Enter account number: ");
  11.         accountNumber = scanner.nextLine();
  12.  
  13.         System.out.print("Enter initial balance: ");
  14.         balance = scanner.nextDouble();
  15.     }
  16.  
  17.     public void deposit() {
  18.         Scanner scanner = new Scanner(System.in);
  19.  
  20.         System.out.print("Enter the amount to deposit: ");
  21.         double amount = scanner.nextDouble();
  22.  
  23.         balance += amount;
  24.         System.out.println("Deposit successful. New balance: " + balance);
  25.     }
  26.  
  27.     public void withdraw() {
  28.         Scanner scanner = new Scanner(System.in);
  29.  
  30.         System.out.print("Enter the amount to withdraw: ");
  31.         double amount = scanner.nextDouble();
  32.  
  33.         if (balance >= amount) {
  34.             balance -= amount;
  35.             System.out.println("Withdrawal successful. New balance: " + balance);
  36.         } else {
  37.             System.out.println("Insufficient funds. Withdrawal failed.");
  38.         }
  39.     }
  40.  
  41.     public void displayAccountInfo() {
  42.         System.out.println("Account Number: " + accountNumber);
  43.         System.out.println("Balance: " + balance);
  44.     }
  45.  
  46.     public static void main(String[] args) {
  47.         SimpleBank bank = new SimpleBank();
  48.         bank.createAccount();
  49.  
  50.         System.out.println("Select an option:");
  51.         System.out.println("1. Deposit");
  52.         System.out.println("2. Withdraw");
  53.  
  54.         Scanner scanner = new Scanner(System.in);
  55.         int choice = scanner.nextInt();
  56.  
  57.         if (choice == 1) {
  58.             bank.deposit();
  59.         } else if (choice == 2) {
  60.             bank.withdraw();
  61.         } else {
  62.             System.out.println("Invalid choice.");
  63.         }
  64.  
  65.         bank.displayAccountInfo();
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement