Results 1 to 5 of 5
Thread: help bankaccount.
- 03-20-2011, 05:48 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
help bankaccount.
hi please help with this bankaccount assignment i have.
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
-
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, 06:21 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
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, 06:22 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
yes thats what i want it to do but cant come up with a solution:S
- 03-20-2011, 06:32 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.Last edited by sunde887; 03-20-2011 at 06:40 AM.
Similar Threads
-
BankAccount, how to reject negative amounts? PLEASE HELP!
By armedrabbit in forum New To JavaReplies: 6Last Post: 03-07-2011, 03:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks