SHARE
TWEET

Untitled

a guest Nov 9th, 2019 147 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Account.java
  2.  
  3. import java.text.NumberFormat;
  4. import java.util.Random;
  5. /**
  6. * The class Account represents a generic account
  7. * @author Justin Herrera
  8. * generated Nov. 1st. 2019
  9. * @version 1.8.0_221
  10. * @since 1.0
  11. *  description of the class/file about its main features,and usage specifications / examples
  12. */
  13. public class Account{
  14. private final double RATE = 0.035;  // interest rate of 3.5%
  15. private long acctNumber;
  16. private double balance;
  17. private String name;
  18. private static double newAccount;
  19. private static double consolidatedBalance;
  20.  
  21. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  22.  
  23. //-----------------------------------------------------------------
  24. //  Sets up the account by defining its owner, account number,
  25. //  and initial balance.
  26. //-----------------------------------------------------------------
  27. /**
  28.  *  Account constructor with all fields as parameters
  29.  * @param owner the owner of the account
  30.  * @param account the specific account
  31.  * @param initial is the new balance of the account
  32.  */
  33. public Account(String owner, long account, double initial)
  34. {
  35.     balance = initial;
  36.     name = owner;
  37.     acctNumber = account;
  38.    
  39. }
  40. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. /**
  42.  * @param initBal is the original balance of the users account
  43.  * @param owner is the name of person owning the account
  44.  * @param number the random generated account number of the user
  45.  */
  46. public Account (double initBal, String owner, long number) {
  47.     Random rand = new Random();
  48.     balance = initBal;
  49.     name = owner;
  50.     number = Math.abs(rand.nextLong());
  51.     this.acctNumber = number;
  52. }
  53. /**
  54.  * @param initBal Initializes the owner as specified
  55.  * @param owner sets the initial balance to 0 and randomly generates the account number
  56.  */
  57. public Account (double initBal, String owner) {
  58.     Random rand = new Random();
  59.     balance = initBal;
  60.     name = owner;
  61.     this.acctNumber = Math.abs(rand.nextLong());
  62. }
  63. /**
  64.  *
  65.  * @param owner sets the initial balance to 0 and randomly generates the account number
  66.  */
  67. public Account (String owner) {
  68.     balance = 0;
  69.     name = owner;
  70.     Random rand = new Random();      
  71.     this.acctNumber = Math.abs(rand.nextLong());
  72. }
  73.  
  74. public Account(String name,String name2) {
  75.     // TODO Auto-generated constructor stub
  76. }
  77. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. //-----------------------------------------------------------------
  79. //  Deposits the specified amount into the account. Returns the
  80. //  new balance.
  81. //-----------------------------------------------------------------
  82. /**
  83.  * @param amount is the value that will be added or subtracted to the account
  84.  * @return returns the balance after the values have been added or subtracted
  85.  */
  86. public double deposit(double amount)
  87. {
  88.     balance = balance + amount;
  89.     return balance;
  90. }
  91.  
  92. //-----------------------------------------------------------------
  93. //  Withdraws the specified amount from the account. Returns the new balance.
  94. //-----------------------------------------------------------------
  95. /**
  96. * @param amount is the amount being pulled from the users account
  97. * @return returns the new amount after being subtracted by the withdrawal
  98. */
  99. public double withdraw(double amount)
  100. {
  101.     balance = balance - amount;
  102.     return balance;
  103. }
  104. /**
  105.  * @param amount is the amount being pulled from the users account
  106.  * @param fee is the a service charge for withdrawing funds
  107.  * @return shows the new initial balance after the fee
  108.  */
  109. public double withdraw(double amount, double fee)
  110. {
  111.     balance -=  amount;
  112.     balance -= fee;
  113.     return balance;
  114. }
  115.  
  116. //-----------------------------------------------------------------
  117. //  Adds interest to the account and returns the new balance.
  118. //-----------------------------------------------------------------
  119. /**
  120.  *
  121.  * @param balance
  122.  * @param RATE is the fee that
  123.  * @return
  124.  */
  125. public double addInterest(double amount, double RATE)
  126. {
  127.      balance += amount;
  128.      balance = (amount * RATE);
  129.      return balance;
  130. }
  131.  
  132. //-----------------------------------------------------------------
  133. //  Returns the current balance of the account.
  134. //-----------------------------------------------------------------
  135. /**
  136.  *
  137.  * @return
  138.  */
  139. public double getBalance()
  140. {
  141.     return balance;
  142. }
  143. //-----------------------------------------------------------------//
  144. //Closes account                                                   //
  145. //-----------------------------------------------------------------//
  146. public static void close(Account account) {
  147. //public static void closeAcc(String account) {
  148.      
  149.     account.name += "Closed";
  150.     account.balance = 0.0;
  151.    
  152.   }
  153. /**
  154.  *
  155.  * @param acct1
  156.  * @param acct2
  157.  * @return
  158.  */
  159.  
  160.  
  161. /*public static double AccountConsolidate(Account acct1, Account acct2)
  162. {
  163. newAccount = acct1.getBalance() + acct2.getBalance();
  164.  
  165. String name1 = acct1.getName();
  166. String name2 = acct2.getName();
  167. if(name1.equals(name2));
  168. newAccount = newAccount.getAcctNumber();
  169.  
  170. return newAccount;
  171. }
  172.  
  173. */
  174.  
  175.  
  176.   public static Account consolidate(Account acct, Account acct2)
  177. {
  178.   if (acct.name != acct2.name && acct.acctNumber != acct2.acctNumber)  
  179.   {
  180.       Account consolidatedAccount = new Account(acct.name, acct2.name);    
  181.       double actbal = acct.getBalance();
  182.       double actbal2 = acct2.getBalance();  
  183.       consolidatedBalance = actbal + actbal2;
  184.       consolidatedAccount.balance = consolidatedBalance;
  185.      // consolidatedAccount.newAccount();
  186.    
  187.    
  188.       return consolidatedAccount ;     
  189.   }
  190.   else
  191.   {  
  192.     System.out.println("Cannot consolidate, either names do not match or account numbers are the same");
  193.     return null;
  194.   }
  195.   }
  196.  
  197. /**
  198.  * @return
  199.  */
  200. public long getAcctNumber(){
  201.    
  202.     return acctNumber;
  203. }
  204. /**
  205.  *
  206.  * @return
  207.  */
  208. public String getName() {
  209.    
  210.     return name;
  211. }
  212.  
  213. //  Returns a one-line description of the account as a string.
  214. //-----------------------------------------------------------------
  215. /**
  216.  *
  217.  */
  218.  
  219. public String toString()
  220.     {
  221.             NumberFormat fmt = NumberFormat.getCurrencyInstance();
  222.         return (acctNumber + "\t" + name + "\t" + fmt.format(balance));
  223.     }
  224. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top