(a) Assume that in a certain country, tax is payable at the following rates: 15%
ID: 665705 • Letter: #
Question
(a) Assume that in a certain country, tax is payable at the following rates: 15% on your first $50000 income 25% on any amount over $50000 Write a method that takes in an annual income value and returns the amount of tax payable. The method should have the following signature: public float tax(int income) (5 marks) (b) Given below is a Java method: Suppose that we have an int array defined as follows: What will be printed if mystery(a, 6) is called? (3 marks) (e) Rewrite the method in (b) using a while loop.Explanation / Answer
a)
public float tax(int income)
{
float tax_payable=0;
if(income<50000)
tax_payable=(income*15)/100;
else
tax_payable=(income*25)/100;
return tax_payable;
}
b)
output will be:
number[0]=10
number[1]=15
number[4]=2
number[5]=7
c)
public void mystery(int [] number,int n)
{
int i=0;
while(i<=n)
{
if(number[i]<0 || number[i]>15)
i++;
else
System.out.println("number["+i+"]="+number[i]);
i++;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.