Nikki12345671

BankAccount

Mar 28th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1.  
  2. public class Program {
  3.  
  4. public static void main(String[] args) {
  5. // Nikki Forehand
  6. //March 27, 2019
  7.  
  8. BankAccount myMoney = new BankAccount(500,9999);
  9.  
  10. myMoney.withdraw(10, 99990);
  11. myMoney.withdraw(-5, 8888);;
  12. myMoney.withdraw(90, 99990);
  13.  
  14. System.out.println(myMoney.getBalance());
  15. }
  16.  
  17. }
  18.  
  19. class BankAccount {
  20. private double balance;
  21. private int pin;
  22.  
  23. public BankAccount(double startingBalance, int newPin) {
  24. balance = startingBalance;
  25. pin = newPin;
  26.  
  27. }
  28.  
  29. public double getBalance() {
  30. return balance;
  31. }
  32.  
  33.  
  34. public void withdraw(double amount, int p) {
  35. if (p==pin) {
  36. if (amount > 0) {
  37. balance = balance - amount;
  38. System.out.println ("Money dispensed. New balance: $" + balance);
  39. }
  40. else {
  41. System.out.println ("Error: Amount must be greater than $0\"");
  42. }
  43. }
  44. else {
  45. System.out.println ("Error: PIN Incorrect");
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment