CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2009
    Posts
    3

    Please check my code

    Hi everyone,

    Could someone please check my answer forthe question below and tell me if it is correct.

    Implement a method showTaxAmount to show the tax paid for payment amount from 1000 to 55000 with incremental of 100.

    Answer

    Code:
    public void showTaxAmount(int payment)
    {
         if (payment >= 1000 && payment <= 55000 && (payment%100 == 0) )
            {
             System.out.println("Tax paid for " + payment + " is "+ payment*TAX_RATE);
            }
        else
            {
              System.out.println("Payment should be from 1000 to 55000 with incremental of 100");
            }
    }
    Thank you all very much.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Please check my code

    First question to ask is 'Does it work?'.

    Have you tried stepping through the code by hand, keeping track of the variables and their values on paper? Do you get the correct results?

    Have you tried to run the code? If it compiles, then there are no syntax errors. If it runs correctly there are no logic errors. Have you tried running this code? Does it give the correct answers?

    I can't tell if it is right, because I don't know what TAX_RATE is. If TAX_RATE is declared correctly, and has the correct value, then the code will work as expected.

    Judge a man by his questions, rather than his answers...
    Voltaire
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Jul 2009
    Posts
    3

    Re: Please check my code

    Thank you dlorde,

    The code compiles and runs as expected.

    But a forummer suggested that I need a loop for this question because it states "increments of 100".

    So this question is solved.

    Thank you for your input, highly appreciated.

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Please check my code

    Quote Originally Posted by kumaran21 View Post
    But a forummer suggested that I need a loop for this question because it states "increments of 100".
    I can understand that - it isn't clear in the question what 'incremental of 100' means - I guessed it from the code you wrote...

    However, in programming, regular increments usually mean iteration with addition, so the question could be interpreted as asking for code that displays the tax paid for all the values from 1000 to 55000 in increments of 100, in which case you would have to wrap the current method code in a loop. It is a poorly worded and ambiguous question.

    Good teaching is more a giving of the right questions than a giving of the right answers...
    J. Albers
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured