Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Account.java
- import java.text.NumberFormat;
- import java.util.Random;
- /**
- * The class Account represents a generic account
- * @author Justin Herrera
- * generated Nov. 1st. 2019
- * @version 1.8.0_221
- * @since 1.0
- * description of the class/file about its main features,and usage specifications / examples
- */
- public class Account{
- private final double RATE = 0.035; // interest rate of 3.5%
- private long acctNumber;
- private double balance;
- private String name;
- private static double newAccount;
- private static double consolidatedBalance;
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //-----------------------------------------------------------------
- // Sets up the account by defining its owner, account number,
- // and initial balance.
- //-----------------------------------------------------------------
- /**
- * Account constructor with all fields as parameters
- * @param owner the owner of the account
- * @param account the specific account
- * @param initial is the new balance of the account
- */
- public Account(String owner, long account, double initial)
- {
- balance = initial;
- name = owner;
- acctNumber = account;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /**
- * @param initBal is the original balance of the users account
- * @param owner is the name of person owning the account
- * @param number the random generated account number of the user
- */
- public Account (double initBal, String owner, long number) {
- Random rand = new Random();
- balance = initBal;
- name = owner;
- number = Math.abs(rand.nextLong());
- this.acctNumber = number;
- }
- /**
- * @param initBal Initializes the owner as specified
- * @param owner sets the initial balance to 0 and randomly generates the account number
- */
- public Account (double initBal, String owner) {
- Random rand = new Random();
- balance = initBal;
- name = owner;
- this.acctNumber = Math.abs(rand.nextLong());
- }
- /**
- *
- * @param owner sets the initial balance to 0 and randomly generates the account number
- */
- public Account (String owner) {
- balance = 0;
- name = owner;
- Random rand = new Random();
- this.acctNumber = Math.abs(rand.nextLong());
- }
- public Account(String name,String name2) {
- // TODO Auto-generated constructor stub
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //-----------------------------------------------------------------
- // Deposits the specified amount into the account. Returns the
- // new balance.
- //-----------------------------------------------------------------
- /**
- * @param amount is the value that will be added or subtracted to the account
- * @return returns the balance after the values have been added or subtracted
- */
- public double deposit(double amount)
- {
- balance = balance + amount;
- return balance;
- }
- //-----------------------------------------------------------------
- // Withdraws the specified amount from the account. Returns the new balance.
- //-----------------------------------------------------------------
- /**
- * @param amount is the amount being pulled from the users account
- * @return returns the new amount after being subtracted by the withdrawal
- */
- public double withdraw(double amount)
- {
- balance = balance - amount;
- return balance;
- }
- /**
- * @param amount is the amount being pulled from the users account
- * @param fee is the a service charge for withdrawing funds
- * @return shows the new initial balance after the fee
- */
- public double withdraw(double amount, double fee)
- {
- balance -= amount;
- balance -= fee;
- return balance;
- }
- //-----------------------------------------------------------------
- // Adds interest to the account and returns the new balance.
- //-----------------------------------------------------------------
- /**
- *
- * @param balance
- * @param RATE is the fee that
- * @return
- */
- public double addInterest(double amount, double RATE)
- {
- balance += amount;
- balance = (amount * RATE);
- return balance;
- }
- //-----------------------------------------------------------------
- // Returns the current balance of the account.
- //-----------------------------------------------------------------
- /**
- *
- * @return
- */
- public double getBalance()
- {
- return balance;
- }
- //-----------------------------------------------------------------//
- //Closes account //
- //-----------------------------------------------------------------//
- public static void close(Account account) {
- //public static void closeAcc(String account) {
- account.name += "Closed";
- account.balance = 0.0;
- }
- /**
- *
- * @param acct1
- * @param acct2
- * @return
- */
- /*public static double AccountConsolidate(Account acct1, Account acct2)
- {
- newAccount = acct1.getBalance() + acct2.getBalance();
- String name1 = acct1.getName();
- String name2 = acct2.getName();
- if(name1.equals(name2));
- newAccount = newAccount.getAcctNumber();
- return newAccount;
- }
- */
- public static Account consolidate(Account acct, Account acct2)
- {
- if (acct.name != acct2.name && acct.acctNumber != acct2.acctNumber)
- {
- Account consolidatedAccount = new Account(acct.name, acct2.name);
- double actbal = acct.getBalance();
- double actbal2 = acct2.getBalance();
- consolidatedBalance = actbal + actbal2;
- consolidatedAccount.balance = consolidatedBalance;
- // consolidatedAccount.newAccount();
- return consolidatedAccount ;
- }
- else
- {
- System.out.println("Cannot consolidate, either names do not match or account numbers are the same");
- return null;
- }
- }
- /**
- * @return
- */
- public long getAcctNumber(){
- return acctNumber;
- }
- /**
- *
- * @return
- */
- public String getName() {
- return name;
- }
- // Returns a one-line description of the account as a string.
- //-----------------------------------------------------------------
- /**
- *
- */
- public String toString()
- {
- NumberFormat fmt = NumberFormat.getCurrencyInstance();
- return (acctNumber + "\t" + name + "\t" + fmt.format(balance));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement