Write a program that takes as input the marital status (\"single\" or \"married\
ID: 3595988 • Letter: W
Question
Write a program that takes as input the marital status ("single" or "married", case insensitive) and the taxable income (double), and computes taxes for the following schedule. If your status is Single and But not The tax isOf the if the taxable income is over over S0 $8,000 $32,000 If your status is Married and But not The tax is of the if the taxable income is over over amount over $0 $8,000 $32,000 8, 000 32,000$800+ $4,400+ amount over $0 $0 $16, 000 $64, 000 $16, 000 $64, 000 $1,600+ $8,800+ 16,000 $64, 000 For example, if David is single and his taxable income is $10,000, then his income tax will be $800 + 15% of ($10,000-$8,000)-$1,100 The following are examples of the required /O behavior, where the user's input is shown in bold. fcsang@fluffy ~/cs140/project $ java Tax Enter your marital status (single or married): sinGLE Enter your taxable income: 10000 Your income tax is $1,100.00Explanation / Answer
public class TaxCalculation
{
private double calculateTax(String s, double income )
{
/* calculating tax as per given table of information */
/* for singles */
if( s.equalsIgnoreCase("SINGLE") && income > 0 && income <= 8000)
return (10/100)*(income);
else if( s.equlasIgnoreCase("SINGLE") && income > 8000 && income <= 32000)
return (800 + (15/100) * ( income - 8000 ));
else if (s.equalsIgnoreCase("SINGLE") && income > 32000 )
return (4400 + (25/100)*(income -32000));
/* for married */
else if (s.equalsIgnoreCase("MARRIED") && income > 0 && income <= 16000)
return (10/100)*income;
else if ( s.equalsIgnoreCase("MARRIED") && income > 16000 && income <= 64000)
return (1600 + (15/100) * (income - 16000) );
else if ( s.equalsIgnoreCase("MARRIED") && income > 64000 )
return (8800 + (25/100) * ( income - 64000 ) );
/* if not matched above case */
else
return -1;
}
public static void main( String args[])
{
String name;
double income;
Scanner s = new Scanner(System.in);
System.out.println("Enter your marital status (single or married):");
name = s.readLine();
System.out.println("Enter your taxable income :");
income = Double.parseDouble(s.readLine());
if(calculateTax(name,income) != -1)
System.out.println("Your income tax is :" + calculateTax(name,income));
else
System.out.println("Enter valid details!");
}
}
/* I hope this is clear */
/* if any doubt please comment */
/* thank you */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.