Monty374

Account

Nov 14th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. package bank;
  2.  
  3. /**
  4. * Account class.
  5. */
  6.  
  7. import java.text.NumberFormat;
  8.  
  9. public class Account {
  10. private double balance;
  11. private Customer cust;
  12.  
  13.  
  14. /**
  15. * constructor
  16. * pre: none
  17. * post: An account has been created. Balance and
  18. * customer data has been initialized with parameters.
  19. */
  20. public Account(double bal, String fName, String lName, String str, String city, String st, String zip) {
  21. balance = bal;
  22. cust = new Customer(fName, lName, str, city, st, zip);
  23. }
  24.  
  25. public void changeAddress(String str, String city, String st, String zip) {
  26. cust.changeStreet(str);
  27. cust.changeCity(city);
  28. cust.changeState(st);
  29. cust.changeZIP(zip);
  30. }
  31.  
  32. /**
  33. * Returns the current balance.
  34. * pre: none
  35. * post: The account balance has been returned.
  36. */
  37. public double getBalance() {
  38. return(balance);
  39. }
  40.  
  41.  
  42. /**
  43. * A deposit is made to the account.
  44. * pre: none
  45. * post: The balance has been increased by the amount of the deposit.
  46. */
  47. public void deposit(double amt) {
  48. balance += amt;
  49. }
  50.  
  51.  
  52. /**
  53. * A withdrawal is made from the account if there is enough money.
  54. * pre: none
  55. * post: The balance has been decreased by the amount withdrawn.
  56. */
  57. public void withdrawal(double amt) {
  58. if (amt <= balance) {
  59. balance -= amt;
  60. } else {
  61. System.out.println("Not enough money in account.");
  62. }
  63. }
  64.  
  65.  
  66.  
  67. /**
  68. * Returns a String that represents the Account object.
  69. * pre: none
  70. * post: A string representing the Account object has
  71. * been returned.
  72. */
  73. public String toString() {
  74. String accountString;
  75. NumberFormat money = NumberFormat.getCurrencyInstance();
  76.  
  77. accountString = cust.toString();
  78. accountString += "Current balance is " + money.format(balance);
  79. return(accountString);
  80. }
  81. }
Add Comment
Please, Sign In to add comment