Results 1 to 5 of 5
  1. #1
    YNWA is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default 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

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    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...

  3. #3
    YNWA is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    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;
    }
    }

  4. #4
    YNWA is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    yes thats what i want it to do but cant come up with a solution:S

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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 07:40 AM.

Similar Threads

  1. BankAccount, how to reject negative amounts? PLEASE HELP!
    By armedrabbit in forum New To Java
    Replies: 6
    Last Post: 03-07-2011, 04:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •