Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SimpleBank {
- private String accountNumber;
- private double balance;
- public void createAccount() {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Enter account number: ");
- accountNumber = scanner.nextLine();
- System.out.print("Enter initial balance: ");
- balance = scanner.nextDouble();
- }
- public void deposit() {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Enter the amount to deposit: ");
- double amount = scanner.nextDouble();
- balance += amount;
- System.out.println("Deposit successful. New balance: " + balance);
- }
- public void withdraw() {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Enter the amount to withdraw: ");
- double amount = scanner.nextDouble();
- if (balance >= amount) {
- balance -= amount;
- System.out.println("Withdrawal successful. New balance: " + balance);
- } else {
- System.out.println("Insufficient funds. Withdrawal failed.");
- }
- }
- public void displayAccountInfo() {
- System.out.println("Account Number: " + accountNumber);
- System.out.println("Balance: " + balance);
- }
- public static void main(String[] args) {
- SimpleBank bank = new SimpleBank();
- bank.createAccount();
- System.out.println("Select an option:");
- System.out.println("1. Deposit");
- System.out.println("2. Withdraw");
- Scanner scanner = new Scanner(System.in);
- int choice = scanner.nextInt();
- if (choice == 1) {
- bank.deposit();
- } else if (choice == 2) {
- bank.withdraw();
- } else {
- System.out.println("Invalid choice.");
- }
- bank.displayAccountInfo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement