Question

In: Computer Science

The L&L bank can handle up to 30 customers who have savings accounts. Design and implement...

The L&L bank can handle up to 30 customers who have savings accounts. Design and implement a program that manages the accounts. Keep track of key information and let each customer make deposits and withdrawals. Produce error messages for invalid transactions. Hint: You may want to base your accounts on the Account class from chapter 5. Also provide a method to add 3 percent interest to all accounts whenever the method is invoked.

This is the account class in chapter 5:

Please use an array for all accounts. Thank you!

import java.text.NumberFormat;

public class Accounts
{



private NumberFormat fmt = NumberFormat.getCurrencyInstance();

   private final double RATE = 0.035;  // interest rate of 3.5%

   private int acctNumber;
   private double balance;
   private String name;

   //-----------------------------------------------------------------
   //  Sets up the account by defining its owner, account number,
   //  and initial balance.
   //-----------------------------------------------------------------
   public Accounts (String owner, int account, double initial)
   {
      name = owner;
      acctNumber = account;
      balance = initial;
   }

   //-----------------------------------------------------------------
   //  Validates the transaction, then deposits the specified amount
   //  into the account. Returns the new balance.
   //-----------------------------------------------------------------
   public double deposit (double amount)
   {
      if (amount < 0)  // deposit value is negative
      {
         System.out.println ();
         System.out.println ("Error: Deposit amount is invalid.");
         System.out.println (acctNumber + "  " + fmt.format(amount));
      }
      else
         balance = balance + amount;
      return balance;
   }

   //-----------------------------------------------------------------
   //  Validates the transaction, then withdraws the specified amount
   //  from the account. Returns the new balance.
   //-----------------------------------------------------------------


     public double withdraw (double amount, double fee)
       {
          amount += fee;

      if (amount < 0)  // withdraw value is negative
      {
         System.out.println ();
         System.out.println ("Error: Withdraw amount is invalid.");
         System.out.println ("Account: " + acctNumber);
         System.out.println ("Requested: " + fmt.format(amount));
      }
      else
         if (amount > balance)  // withdraw value exceeds balance
         {
            System.out.println ();
            System.out.println ("Error: Insufficient funds.");
            System.out.println ("Account: " + acctNumber);
            System.out.println ("Requested: " + fmt.format(amount));
            System.out.println ("Available: " + fmt.format(balance));
         }
         else
            balance = balance - amount;

      return balance;
   }

   //-----------------------------------------------------------------
   //  Adds interest to the account and returns the new balance.
   //-----------------------------------------------------------------
   public double addInterest ()
   {
      balance += (balance * RATE);
      return balance;
   }

   public double addInterestAll ()// I made this method myself but I am not sure if it is correct
   {
       balance += (balance * 0.03);
       return balance;
   }

   //-----------------------------------------------------------------
   //  Returns the current balance of the account.
   //-----------------------------------------------------------------
   public double getBalance ()
   {
      return balance;
   }

   //-----------------------------------------------------------------
   //  Returns the account number.
   //-----------------------------------------------------------------
   public int getAccountNumber ()
   {
      return acctNumber;
   }

   //-----------------------------------------------------------------
   //  Returns a one-line description of the account as a string.
   //-----------------------------------------------------------------
   public String toString ()
   {
      return (acctNumber + "\t" + name + "\t" + fmt.format(balance));
   }
}

Solutions

Expert Solution

Below is the account manager class

/**
*
* Accounts manager class to manage all the
* properties of accounts
*
*/
public class AccountsManager {
private Accounts[] accounts;
private final int capacity;
private int current;
private double fee;
//we give the total capacity of accounts
public AccountsManager(int capacity) {
this.capacity = capacity;
accounts = new Accounts[capacity];
current = 0;
}

// returns the account number of the new account
// or -1 if no account could be made
//account number starts with 0
public int addAccount(String name) {
if (current >= capacity) {
return -1;
}
accounts[current] = new Accounts(name, current, 0);
return current++;
}
//return the account details based on the account number
public Accounts getAccount(int number) {
if (number >= current || number < 0) {
return null;
}
return accounts[number];
}
//make the deposit into the given account number and with the given amount
public double makeDeposit(int accountNumber, double amount) {
   Accounts account = getAccount(accountNumber);
  
   return account.deposit(amount);
}
//this is to withdraw the amount, withdrawl fee is set from main method
public double withdrawAmount(int accountNumber, double amount) {
   Accounts account = getAccount(accountNumber);
  
   return account.withdraw(amount, fee);
}
  
public void addInterestToAll() {
   for (int i=0; i <= current-1; i++) {
       System.out.println("i: " + i + "account length: " + current);
       System.out.println("Interest added to " + accounts[i].getAccountNumber() + " is : "+ accounts[i].addInterest());
   }
}

   public double getFee() {
       return fee;
   }

   public void setFee(double fee) {
       this.fee = fee;
   }
}

below is the main method class used for testing


public class Main {

   public static void main(String[] args) {
       AccountsManager manager = new AccountsManager(30);
       manager.setFee(2.0);
       System.out.println("accounts");
       manager.addAccount("HSK");
       System.out.println(manager.getAccount(0));
       manager.addAccount("Saras");
       System.out.println(manager.getAccount(1));
      
       manager.makeDeposit(0, 20.0);
       manager.makeDeposit(1, 40.0);
       System.out.println("made deposits");
       System.out.println(manager.getAccount(0));
       System.out.println(manager.getAccount(1));
      
       System.out.println("withdrawls");
       manager.withdrawAmount(0, 5.0);
       manager.withdrawAmount(1, 2.0);
       System.out.println(manager.getAccount(0));
       System.out.println(manager.getAccount(1));
      
       System.out.println("adding interest");
       manager.addInterestToAll();
       System.out.println(manager.getAccount(0));
       System.out.println(manager.getAccount(1));
   }
}


Related Solutions

A bank teller can handle 40 customers an hour and customers arrive every six minutes. What...
A bank teller can handle 40 customers an hour and customers arrive every six minutes. What is the average time a customer spends waiting in line? a. 15 seconds b. 0.40 minutes c. 1.25 minutes d. 30 seconds Customers arrive at a bakery at an average rate of 18 per hour on week day mornings. Each clerk can serve a customer in an average of three minutes. How long does each customer wait in the system? a. 1 hour b....
A study by a bank compared the mean savings of customers who were depositors for three...
A study by a bank compared the mean savings of customers who were depositors for three years or less, with those who had been depositors for more than three years. The results of a sample are: Depositors 3 years or less, sample size=100, mean saving balance=$1200, Population standard variation=$100 Depositors more than 3 years, sample size=150, mean saving balance=$1250, Population standard variation=$250 At the 0.10 significance level, can we conclude that those who had been depositing for more than three...
A study by a bank compared the mean savings of customers who were depositors for three...
A study by a bank compared the mean savings of customers who were depositors for three years or less, with those who had been depositors for more than three years. The results of a sample are: Depositors 3 years or less, sample size=100, mean saving balance=$1200, Population standard variation=$100 Depositors more than 3 years, sample size=150, mean saving balance=$1250, Population standard variation=$250 At the 0.10 significance level, can we conclude that those who had been depositing for more than three...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads in the principle 2) reads in additional money deposited each year (treat this as a constant) 3) reads in years to grow, and 4) reads in interest rate And then finally prints out how much money they would have each year. See below for formatting. Enter the principle: XX Enter the annual addition: XX Enter the number of years to grow: XX Enter the...
Question B2 (30 pts): Customers arrive to Lincoln Savings Bank (LSB) with an average rate of...
Question B2 (30 pts): Customers arrive to Lincoln Savings Bank (LSB) with an average rate of 3 customers per minute. The average time a teller takes to serve a customer is 5 minutes. Standard deviation of customer inter-arrival time is 1.5 minutes and standard deviation of service time is 3 minutes. LSB employs 20 tellers. All customers form a single waiting line and can be served by any of the tellers in a first-come-first-serve basis as tellers become available. For...
There are two kinds of bank accounts: checking and savings. You can deposit to (i.e. add...
There are two kinds of bank accounts: checking and savings. You can deposit to (i.e. add money in) or withdraw (i.e. take money out) from an account. A checking account can be withdrawn with an unlimited number of times. A savings account can only be withdrawn at most N times per calendar month. Checking accounts have no monthly fee. Savings accounts have a fixed monthly fee X. But if you deposit at least a money amount of M each month,...
Write a program to simulate a bank transaction. There are two bank accounts: checking and savings....
Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the transactions; options are deposit, withdrawal, and transfer. Then ask for the account; options are checking and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts. in if and else statments only in c++
assigsment-Write a program to simulate a bank transaction. There are two bank accounts: checking and savings....
assigsment-Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the transactions; options are deposit, withdrawal, and transfer. Then ask for the account; options are checking and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts. in c++ work done- output and need help with the...
List the owner's name of all male customers in the bank who have a ’Checking’ account....
List the owner's name of all male customers in the bank who have a ’Checking’ account. Find all accounts associated with ’Alexander Felix’. For each account of the previous question, compute the Balance, and return a table that shows the account number, type, and balance for each account (hint: use UNION). The list of customer names that have transactions greater than or equal to one thousand dollars. Bank.sql is under this statement. DROP DATABASE IF EXISTS Bank; CREATE DATABASE Bank;...
List the owner's name of all male customers in the bank who have a ’Checking’ account....
List the owner's name of all male customers in the bank who have a ’Checking’ account. Find all accounts associated with ’Alexander Felix’. For each account of the previous question, compute the Balance, and return a table that shows the account number, type, and balance for each account (hint: use UNION). The list of customer names that have transactions greater than or equal to one thousand dollars. A) Answer this question using only nested queries (i.e., each select is over...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT