Results 1 to 8 of 8
  1. #1
    PedramCarter is offline Member
    Join Date
    Nov 2014
    Posts
    27
    Rep Power
    0

    Default How do I create a withdraw/deposit feature so it can't exceed the maximum limit(read)

    So lets say I got maximum of 20 deposit, I want to create a method/function (idk what proper name for it is) so that you cannot deposit more than 20 nor withdraw more than you have in your account, so this function checks your account, if your total is for example 18 and you're trying to deposit 10, it rejects it and doesn't add to your total and pops up with a message, vice versa for withdraw.
    this is what I have so far

    Not I already have the maximum limit + total feature created just not displayed here

    Java Code:
        public void depositMoney (int dMoney)
        {
        if(DMoney > 0 ) {
            totalMoney = totalMoney + dMoney;
        }
        else {
            System.out.println("Please insert money more than 0");
        }
        {
        if (totalMoney > maxMoney)
        System.out.println("You have exceeded the capacity of your bankacc limit");
             
         
       
           }
    
    
        }
        public void withdrawmoney (int wMoney)
        {
        if(wMoney > 0 ) {
            totalMoney = totalMoney - wmoney;
        }
        else {
            System.out.println("Please insert withdraw in correct figures");
    Last edited by Tolls; 11-25-2014 at 05:46 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: How do I create a withdraw/deposit feature so it can't exceed the maximum limit(r

    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    PedramCarter is offline Member
    Join Date
    Nov 2014
    Posts
    27
    Rep Power
    0

    Default Re: How do I create a withdraw/deposit feature so it can't exceed the maximum limit(r

    What is this I don't understand?, aren't these 2 different type of websites? is this not allowed to post on 2 websites? whats going on I thought posting on 2 different community forums would get me more responses.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How do I create a withdraw/deposit feature so it can't exceed the maximum limit(r

    It is allowed, but it is considered a good idea to inform each site where you have posted.
    That way we can avoid repeating the same answers.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    PedramCarter is offline Member
    Join Date
    Nov 2014
    Posts
    27
    Rep Power
    0

    Default Re: How do I create a withdraw/deposit feature so it can't exceed the maximum limit(r

    Quote Originally Posted by Tolls View Post
    It is allowed, but it is considered a good idea to inform each site where you have posted.
    That way we can avoid repeating the same answers.
    Thanks so much, didn't mean to break the forum rules (if I did) apology for double posting.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How do I create a withdraw/deposit feature so it can't exceed the maximum limit(r

    No problem.
    What you need to do for your checks is do them first in the methods.

    At the moment you're doing the check after you've already added/withdrawn the amount.
    So do the check, and return.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    PedramCarter is offline Member
    Join Date
    Nov 2014
    Posts
    27
    Rep Power
    0

    Default Re: How do I create a withdraw/deposit feature so it can't exceed the maximum limit(r

    Quote Originally Posted by Tolls View Post
    No problem.
    What you need to do for your checks is do them first in the methods.

    At the moment you're doing the check after you've already added/withdrawn the amount.
    So do the check, and return.
    Can you give me an example, I'm so sorry I'm totally new to java.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How do I create a withdraw/deposit feature so it can't exceed the maximum limit(r

    No.
    But i will explain the logic...it's even there in your requirements in the first post.
    "(With a max deposit of 20) if your total is for example 18 and you're trying to deposit 10, it rejects it and doesn't add to your total and pops up with a message"

    That statement is your deposit() method in a nutshell.
    It even has the if statement.
    It also has the order.

    Now turn it into a generic statement...not in code, but in words.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. RMI question on withdraw deposit and show balance
    By yousuf89 in forum Networking
    Replies: 1
    Last Post: 05-27-2013, 01:04 PM
  2. How to create a Date feature in Java?
    By rbercovi in forum New To Java
    Replies: 6
    Last Post: 03-04-2010, 09:12 PM

Posting Permissions

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