elvyssoares

Untitled

Oct 11th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class BankAccount {
  2. private int balance;
  3. private String accNum;
  4.  
  5. public BankAccount(String a) {
  6. accNum = a;
  7. balance = 0;
  8. }
  9.  
  10. public void deposit(int amount) {
  11. balance = balance + amount;
  12. }
  13.  
  14. public int getBalance() {
  15. return balance;
  16. }
  17.  
  18. public int withdraw(int amount) throws Exception{
  19. if (balance>=amount){
  20. balance-=amount;
  21. return balance;
  22. }else{
  23. throw new Exception("Insufficient balance");
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment