0% found this document useful (0 votes)
438 views

Bank Account Pojo

This Java class defines a BankAccount with attributes like account number, name, and balance. It includes setter and getter methods to manage these attributes. Methods are provided to deposit, withdraw from, and view the balance of an account. The class displays a menu to users to interact with their account by selecting options like depositing, withdrawing, checking balance, and changing account name.

Uploaded by

syfizz
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
438 views

Bank Account Pojo

This Java class defines a BankAccount with attributes like account number, name, and balance. It includes setter and getter methods to manage these attributes. Methods are provided to deposit, withdraw from, and view the balance of an account. The class displays a menu to users to interact with their account by selecting options like depositing, withdrawing, checking balance, and changing account name.

Uploaded by

syfizz
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.Scanner; /** * Write a description of class BankAccount here.

* * @author (your name) * @version (a version number or a date) */ public class BankAccount { private long accountNumber; private String name; private double balance; /** * Constructor for objects of class BankAccount */ public BankAccount() { } public void setName(String name) { this.name = name; } public void setBalance(double amount) { this.balance = amount; } public void setAccountNumber(long acNo) { this.accountNumber = acNo; } public String getName() { return this.name; } public long getAccountNumber() { return this.accountNumber; } public double getBalance() { return this.balance; } public void deposit(double amount) { if (amount > 0) { this.balance = this.balance + amount; System.out.println("Account credited with an amount of " + amount + ""); System.out.println("Your new account balance is: " + balance); } else { System.out.println("Please supply a valid amount"); } } public void withdraw(double amount) { if (amount < 1) { System.out.println("Please supply a valid amount"); } else if (amount > balance) {

System.out.println("Error Occured: You don't have enough account bal ance to make the transaction"); } else { this.balance = this.balance - amount; } } @Override public String toString() { return "Account_No. :" + this.accountNumber + " Account Holder Name :" + this.name + " Account Balance :" + this.balance; } public void showAccountMenu() { System.out.println("\n*******************************************"); System.out.println("***************ACCOUNT MAIN MENU************"); System.out.println("\n*******************************************"); System.out.println("1. Deposit cash."); System.out.println("2. Withdraw cash."); System.out.println("3. Show account balance"); System.out.println("4. Show my name."); System.out.println("5. Change my name."); System.out.println("6. Go Back to Bank main menu."); System.out.print("Select an option to perform the required operation: " ); String s; int k = -1; Scanner scanIn = new Scanner(System.in); k = Integer.parseInt(scanIn.nextLine()); switch (k) { case 1: System.out.println("You have selected showDepositMenu(); break; case 2: System.out.println("You have selected showWithdrawMenu(); break; case 3: System.out.println("You have selected showMyBalance(); break; case 4: System.out.println("You have selected showMyName(); break; case 5: System.out.println("You have selected showChangeMenu(); break; default: break; } } public void showDepositMenu() { System.out.println("\n*******************************************"); System.out.println("************CASH DEPOSIT SCREEN************");

option :" + k);

option :" + k);

option 3:" + k);

option :" + k);

option :" + k);

System.out.println("\n*******************************************"); System.out.println("Your Current balance is: " + this.balance); System.out.print("Enter the amount to be deposited: "); String s; int k = -1; Scanner scanIn = new Scanner(System.in); double amount = Double.parseDouble(scanIn.nextLine()); this.deposit(amount); showAccountMenu(); } public void showWithdrawMenu() { System.out.println("\n*******************************************"); System.out.println("************CASH WITHDRAW SCREEN************"); System.out.println("\n*******************************************"); System.out.println("Your Current balance is: " + this.balance); System.out.print("Enter the amount to be withdrawn: "); String s; int k = -1; Scanner scanIn = new Scanner(System.in); double amount = Double.parseDouble(scanIn.nextLine()); this.withdraw(amount); showAccountMenu(); } public void showChangeMenu() { System.out.println("\n*******************************************"); System.out.println("************CHANGE NAME SCREEN************"); System.out.println("\n*******************************************"); System.out.println("Your Name is: " + this.balance); System.out.print("Enter the new name: "); String s; int k = -1; Scanner scanIn = new Scanner(System.in); String name = scanIn.nextLine(); this.setName(name); showAccountMenu(); } public void showMyName() { System.out.println("\n*******************************************"); System.out.println("************DISPLAY NAME SCREEN************"); System.out.println("\n*******************************************"); System.out.println("Your Name is: " + this.name); showAccountMenu(); } public void showMyBalance() { System.out.println("\n*******************************************"); System.out.println("************ACCOUNT BALANCE SCREEN************"); System.out.println("\n*******************************************"); System.out.println("Your Account balance is: " + this.balance); showAccountMenu(); } }

You might also like