JackHoughton00

Bank

May 10th, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. package bankquestion;
  2. import java.util.Scanner;
  3. import java.text.NumberFormat;
  4.  
  5. public class BankQuestion {
  6.  
  7. public static void main(String[] args) {
  8. Account munozAccount = new Account(250, "Maria", "Munoz", "110 Glades Road", "Mytown", "FL", "33445");
  9. Scanner input = new Scanner(System.in);
  10. double data;
  11. NumberFormat money = NumberFormat.getCurrencyInstance();
  12.  
  13. System.out.println(munozAccount);
  14.  
  15. System.out.print("Would you like to make changes? (y/n)");
  16. String answer = input.next();
  17.  
  18. if (answer.equals("y")) {
  19. System.out.print("Enter the street: ");
  20. String street = input.next();
  21. System.out.print("Enter the city: ");
  22. String city = input.next();
  23. System.out.print("Enter the state ");
  24. String state = input.next();
  25. System.out.print("Enter the ZIP code: ");
  26. String zip = input.next();
  27. munozAccount.changeAddress(street,city,state,zip);
  28. System.out.println(munozAccount);
  29.  
  30. }
  31.  
  32. System.out.print("Enter deposit amount: ");
  33. data = input.nextDouble();
  34. munozAccount.deposit(data);
  35. System.out.println("Balance is: " + money.format(munozAccount.getBalance()));
  36.  
  37. System.out.print("Enter withdrawal amount: ");
  38. data = input.nextDouble();
  39. munozAccount.withdrawal(data);
  40. System.out.println("Balance is: " + money.format(munozAccount.getBalance()));
  41.  
  42. }
  43. }
  44.  
  45. ********** Account Class **************
  46. package bankquestion;
  47.  
  48. import java.text.NumberFormat;
  49.  
  50. public class Account {
  51. private double balance;
  52. private Customer cust;
  53.  
  54. public Account(double bal, String fName, String lName, String str, String city, String st, String zip) {
  55. balance = bal;
  56. cust = new Customer(fName, lName, str, city, st, zip);
  57. }
  58.  
  59.  
  60. public double getBalance() {
  61. return(balance);
  62. }
  63.  
  64.  
  65. public void deposit(double amt) {
  66. balance += amt;
  67. }
  68. public void changeAddress(String street,String city, String state, String zip) {
  69. cust.changeStreet(street);
  70. cust.changeCity(city);
  71. cust.changeState(state);
  72. cust.changeZip(zip);
  73.  
  74. }
  75.  
  76. public void withdrawal(double amt) {
  77. if (amt <= balance) {
  78. balance -= amt;
  79. } else {
  80. System.out.println("Not enough money in account.");
  81. }
  82. }
  83.  
  84. public String toString() {
  85. String accountString;
  86. NumberFormat money = NumberFormat.getCurrencyInstance();
  87.  
  88. accountString = cust.toString();
  89. accountString += "Current balance is " + money.format(balance);
  90. return(accountString);
  91. }
  92.  
  93. }
  94. ******************Customer Class *****************
  95. package bankquestion;
  96. public class Customer {
  97. private String firstName, lastName, street, city, state, zip;
  98.  
  99.  
  100. public Customer(String fName, String lName, String str, String c, String s, String z) {
  101. firstName = fName;
  102. lastName = lName;
  103. street = str;
  104. city = c;
  105. state = s;
  106. zip = z;
  107. }
  108. public void changeCity(String theCity) {
  109. city = theCity;
  110.  
  111. }
  112. public void changeStreet(String theStreet) {
  113. street = theStreet;
  114. }
  115. public void changeState(String theState) {
  116. state = theState;
  117. }
  118. public void changeZip (String theZip) {
  119. zip = theZip;
  120. }
  121.  
  122.  
  123. public String toString() {
  124. String custString;
  125.  
  126. custString = firstName + " " + lastName + "\n";
  127. custString += street + "\n";
  128. custString += city + ", " + state + " " + zip + "\n";
  129. return(custString);
  130. }
  131. }
Add Comment
Please, Sign In to add comment