# help bankaccount.

• 03-20-2011, 06:48 AM
YNWA
help bankaccount.

i want to find the minimum and maximum balance the account has based on deposits and withdrawals only. Then following that it should also give sum of deposits and sum of withdrawals made so far.

ive finsihed my code for method deposit, withdraw and maximumbalance. but im stuck on minimum balance and sum of deposits and withdrawals.
i have the get methodes i.e return the min max and sums methods when callled upon it.

how do i calculate min balance using if statement? heres my code:

my instance variables

private int balance;

private int deposit ;
private int withdraw;
private double sumOfDeposits;
private double sumOfWithdrawals;
private double maxBalance;
private double minBalance;

my getter methods:

public double getDeposits() {
return sumOfDeposits;
}
public double getWithdrawals()
{
return sumOfWithdrawals;
}

public int getMinimumBalance() {
return minimumBalance;
}

public int getMaximumBalance() {
return maximumBalance;
}

how do i find min, sum of withdrawals and deposits using if statments?
thanks
reem
• 03-20-2011, 07:01 AM
ozzyman
you haven't included enough information in your post, this is what i've made of what you've asked for:

- calculate minimum balance, sum of deposits, and withdrawals
- you have methods to retrieve all of those values already

none of that makes sense so far...
• 03-20-2011, 07:21 AM
YNWA
here is my full code:

public class bankaccount
{
/** i.
* In this Bankaccount it includes; balance, accountName.
*/
private int balance;
private String accountName;
private int deposit ;
private int withdraw;
private int sumOfDeposits;
private int sumOfWithdrawals;
private int maxBalance;
private int minBalance;

/**
* constructors bankaccount with inital balance which ( not negative)
* identifying accountname string.
*/

public BankAccount( String accountname, int newBalance )
{

balance = newBalance ;
accountName = accountname;
}

/**
* method to getBalance i.e the current balance of the bankaccount object.
*/

public int getBalance () {
return balance;
}

/**
* method to get the uniques accountname (String) of an account user.
*/
public String getAccountName () {
return accountName;

}

/**
*Deposit amount which gets added to balance, amount would be not negative
includes maxbalance.
*/

public void deposit(int amount)
{
if ( amount >= 0 )
balance = balance + amount;
else
balance = balance;

if (balance >= maxBalance)
maxBalance = balance;
else maxBalance = maxBalance;

}
/**
* Withdraw amount by decreasing balance.
* @param amount non-negative
*/

public void withdraw(int amount)
{

}

/**
* method which gets the sum of deposits made in an account.
*/
public int getDeposits() {
return sumOfDeposits;
}

/**
*method which returns sum of withdrawals made in an account.
*/
public int getWithdrawals() {
return sumOfWithdrawals;
}

/**
* method returns the minimumBalance in the accounts trans history.
*/

public int getminBalance() {
return minBalance;
}

/**
*method returns the maxbalance in the accounts history.
*/
public int getmaxBalance() {
return maxBalance;
}
}
• 03-20-2011, 07:22 AM
YNWA
yes thats what i want it to do but cant come up with a solution:S
• 03-20-2011, 07:32 AM
sunde887
It won't be too difficult, you may need some more instance variablesto keep track of how the balance changes. The sum of withdrawals should just have something added to them everytime you withdraw/deposit.

Your code doesn't look so bad, the deposit method looks mostly correct and withdraw will be similar. Scratch the idea above of more instance variables, your code is heading in the correct direction, just keep trying and don't be afraid to test it inside main.