Question

One of the big ideas we'll encounter again and again this term is that we can...

One of the big ideas we'll encounter again and again this term is that we can take the value returned by one function and use it as an argument to another function. Let's try it with an example.

Assume that a person's income tax is based on their annual income, their tax bracket (a percentage), and the number of dependents they claim (a person may claim 0 or more dependents). The amount of income tax owed is calculated by multiplying a person's income by their tax bracket, then deducting $1000 for every dependent claimed. For example, if a taxpayer is in the 25% tax bracket and they claim 3 dependents, that person's income tax will be calculated by multiplying their annual income by 0.25, then subtracting $3000. If the calculation results in a negative number, a value of 0 should be produced.

A person's tax bracket is based on that person's annual income and marital status (either single or married). Here are the tax brackets for a single person:

Income Bracket
$0 - $14,999 10%
$15,000 - $49,999 20%
$50,000 - $99,999 25%
$100,000 or more 35%

and here are the brackets for a married person:

Income Bracket
$0 - $31,999 10%
$32,000 - $129,999 20%
$130,000 - $224,999 25%
$225,000 or more 35%

Do the following:

  • (a) Develop a function named bracket that consumes a person's annual income and their marital status (a boolean that's true if the person is single and false if they're married), and produces a percentage (either 0.10, 0.20, 0.25, or 0.35, as described above).
  • (b) Develop a function named tax that consumes a person's annual income, their marital status, and the number of dependents, and produces the amount of income tax owed by that person. The tax function must call the bracket function.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

public class TEST{
public static double bracket(double income,boolean status)
{
if(status==true)
{
if(income<15000)
{
return 0.1;
}
else if(income<50000)
{
return 0.2;
}
else if(income<100000)
{
return 0.25;
}
else
{
return 0.35;
}
}
else
{
if(income<32000)
{
return 0.1;
}
else if(income<130000)
{
return 0.2;
}
else if(income<225000)
{
return 0.25;
}
else
{
return 0.35;
}
}
}
public static double tax(double income,boolean status,int num)
{
double p=bracket(income,status);
double t=p*income-num*1000;
if(t<0)
return 0;
  
return t;
}
public static void main(String []args){

System.out.println("Tax is "+tax(50000,false,5));
}
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
One of the big ideas we'll encounter again and again this term is that we can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT