Jump to content


Check out our Community Blogs

kumaran21

Member Since 23 Oct 2009
Offline Last Active Dec 13 2009 06:48 AM
-----

Posts I've Made

In Topic: Please check my answers on Java module exam

07 December 2009 - 10:53 PM

Is it like this,


int i;
double TAX_RATE = 0.05;

for (i=1000;i<=55000;i+=100)
System.out.println("Tax paid for amount " + i + " is " + i * TAX_RATE);


I tried running this code, and it show a list of tax paid for the amount from 1000 to 55000 with increments of 100.

Is that what the question requires?

In Topic: Please check my answers on Java module exam

06 December 2009 - 05:02 PM

Well I don't have much more than what I have already posted


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


Please correct me if I'm wrong, I thought the code above satisfies the question below.

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

I thought the above code already works like a loop by only accepting values from 1000 to 55000 with increments of 100.

In Topic: Please check my answers on Java module exam

05 December 2009 - 05:34 PM

Hi WingedPanther,

I've been trying to figure out where to implement the if statement for 3 days now, still no joy.

Could you please advice.

In Topic: Please check my answers on Java module exam

01 December 2009 - 09:07 AM

Could you please show me how?

In Topic: Please check my answers on Java module exam

01 December 2009 - 08:47 AM

Someone suggested this,

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

I will try and explain it below. Please correct me if I'm wrong.

Line 1: showTaxAmount method is declared void because this method does not return any values and excepts a value of int type from payment variable.

Line 2: In the if statement all three parameters must be true for Line 3 to be executed

Line 4: the else statement will be executed only when the if statement in line 2 is false.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download