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");
}
}
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 [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
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 [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Bookmarks