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: | 336 Weeks Ago, 5 Days 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