The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
public class BankAccount //Student Starter File
{Â
  private double balance;
  private double transFee;
  private double transactionCount;
  private double freeTransactions;
Â
 /**
  * Constructs a bank account with a zero balance
  */
  public BankAccount()
  { Â
   balance = 0;
   transactionCount=0;
  }
Â
 /**
  * Constructs a bank account with a given balance
  * @param initialBalance the initial balance
  */
  public BankAccount(double initialBalance)
  { Â
   balance = initialBalance;
   transactionCount=0;
  }
Â
 /**
  * Deposits money into the bank account.
  * @param amount the amount to deposit
  */
  public void deposit(double amount)
  {Â
   //double newBalance = balance + amount;
   //balance = newBalance;
   balance = balance+amount;
   transactionCount++;
  }
Â
  /**
  * Withdraws money from the bank account.
  * @param amount the amount to withdraw
  */
  public void withdraw(double amount)
  { Â
   //double newBalance = balance - amount;
   //balance = newBalance;
   balance=balance-amount;
   transactionCount++;
  }
   //setting a fee charged for every transaction and modify the deposit and withdraw methods so that the fee is levied
  public void setTransFee(double amount) Â
  {
   transFee = amount;
   //balance = balance - transFee;
   //balance = newBalance;
  }
  public void setNumFreeTrans(double amount)
  {
   freeTransactions = amount;
  }
Â
  public void deductMonthlyCharge()
  {
   transactionCount = Math.max(transactionCount, freeTransactions);
   transFee = (transactionCount-freeTransactions )*transFee;
   balance = balance-transFee;
  transactionCount=0;
  }
   /**
  * Gets the current balance of the bank account.
  * @return the current balance
  */
  public double getBalance()
  { Â
   return balance;
  }
Â
}
  public class BankAccountTester
{
  public static void main (String [] args)
  {
  BankAccount ab = new BankAccount(1000);
Â
  System.out.println("Set up new account with $1000, 5 free transactions, and $2 per transaction above 5");
  System.out.println("Starting Balance: " + ab.getBalance());
  ab.setTransFee(2.00); //Fee
  ab.setNumFreeTrans(5); //Free Transaction
  System.out.println("deposit 1000, withdraw 500, withdraw 400, deposit 200 - 4 transactions");
  ab.deposit(1000);
  ab.withdraw(500);Â
  ab.withdraw(400);Â
  ab.deposit(200);
  System.out.println("Balance: " + ab.getBalance());Â
  System.out.println("Excepted: 1300.0");Â
  System.out.println("Apply Monthly charge");
  System.out.println("Ending Balance Month 1: " + ab.getBalance());Â
  System.out.println("Excepted: 1300.0n");Â
  System.out.println("Starting Balance: " + ab.getBalance());
  System.out.println("Deposit 1000, withdraw 500, withdraw 400, deposit 200, deposit 500 - 5 transactions");
  ab.deposit(1000);Â
  ab.withdraw(500);Â
  ab.withdraw(400);Â
  ab.deposit(200);
  ab.deposit(500);Â
  System.out.println("Balance: " + ab.getBalance());Â
  System.out.println("Excepted: 2100.0");Â
  System.out.println("Apply Monthly Charge");
  System.out.println("Ending Balance Month 2: " + ab.getBalance());Â
  System.out.println("Excepted: 2100.0n");
  System.out.println("Starting Balance: " + ab.getBalance());
  System.out.println("Deposit 1000, withdraw 500, withdraw 400, deposit 200, deposit 500, withdraw 1000 - 6 transactions" );
  ab.deposit(1000);Â
  ab.withdraw(500);Â
  ab.withdraw(400);Â
  ab.deposit(200);Â
  ab.deposit(500);Â
  ab.withdraw(1000);Â
  System.out.println("Balance: " + ab.getBalance());Â
  System.out.println("Excepted: 1900.0");
  System.out.println("Apply Monthly charge");
  System.out.println("Ending Balance Month 3: " + ab.getBalance());Â
  System.out.println("Excepted: 1898.0n");Â
Â
  System.out.println("Starting Balance: " + ab.getBalance());
  System.out.println("Deposit 1000, withdraw 500, withdraw 400, deposit 200, deposit 500, withdraw 1000, deposit 100 - 7 transactions");
  ab.deposit(1000);Â
  ab.withdraw(500);Â
  ab.withdraw(400);Â
  ab.deposit(200);Â
  ab.deposit(500);Â
  ab.withdraw(1000);Â
  ab.deposit(100);Â
  System.out.println("Balance: " + ab.getBalance());Â
  System.out.println("Excepted: 1798.0");Â
  System.out.println("Apply Monthly Charge");
  System.out.println("Ending Balance Month 4: " + ab.getBalance());Â
  System.out.println("Excepted: 1794.0");
  }
}
Â
Â
Â
Â
didn't get the expect result, can someone fix it?
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly