0

Hi All,

I am new to Java and need some help with my first assignment:

Assignment 1: Taxation Calculator
Specification
Write a program to calculate the tax of an employee. The program should
prompt for a salary and age, and work out the required tax from this data.
These two items will be whole numbers, however the resulting tax calculation
may be a floating-point number.
If the employee is aged 50 or over, their taxable income reduces by 10%.
Taxation Rates
The taxation rates and thresholds are the following:
Taxable Income Tax Calculation
$0 - $6,000 No tax
$6,001 - $21,600 17% on each $1 over $6000
$21,601 - $52,000 $2,652 plus 30% on each $1 over $21,600
$52,001 - $62,500 $11,772 plus 42% on each $1 over $52,000
$62,501 + $16,182 plus 47% on each $1 over $62,500
Sample Execution
For example, the tax calculation for an employee with a salary of $54,000 is:
11772 + (2000 * 0.42) = 12612
If this employee was over 50, their taxable income would be $48,600, and the
calculation would then be:
2652 + (27000 * 0.30) = 10752
The program, when run, might look as such:
Enter the employee’s taxable income: 54000
Enter the employee’s age: 52
Their tax payable is $10752.00

Here is my code:

/* Created on 22/09/2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author Jason Marceau
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/*
 * Created on 19/09/2004
 */

/**
 * @author Jason Marceau
 */
// To test the tax calculation formula
// calculate the tax of an employee
import java.io.*;

public class TaxCalcTest
{
  public static void main(String []args) throws IOException
  {

      // create keyboard input stream
      BufferedReader stdin = new BufferedReader (new
              InputStreamReader (System.in));

      // initialize variables
      String income, age;
      int annual_income, years,
      taxPayable;
      taxPayable = 0 ;

      /* prompt for annual income
       * read income from user into annual_income variable*/
      System.out.print("Enter employee's annual taxable income: ");
      income = stdin.readLine();
      annual_income = Integer.parseInt(income);

      System.out.print("Enter employee's age: ");
      age = stdin.readLine();
      years = Integer.parseInt(income);

      // if over 50 then 10% less tax
          if(years>50)
            annual_income = (annual_income * 10/100);
          else
            taxPayable = annual_income;


      // 1.) <$6000
          if (annual_income<6000 )
            taxPayable = 0;
          else

      // 2.) $6000 - $21,600   
          if (annual_income>6000 && annual_income <21600);
          else
            taxPayable = annual_income * 17/10;

      // 3.) $21,600 - $52,000
          if (annual_income>21600 && annual_income <52000)

          taxPayable =  (annual_income - 52000) * 30/100  + 2652;
          else
      // 4.) $52,001-$62,500
          if (annual_income>52000 && annual_income<62500)

          taxPayable =  (annual_income - 52000) * 42/100  + 11772;
          else

      // 5.) >$62,500
           if (annual_income>62500)
             taxPayable =  (annual_income - 52000) * 47/100  + 16182;
          else
      // display tax payable amount
         System.out.print("Tax payable is:$ " + taxPayable);

          }
      }

Can someone please tell me what I doing wrong to get the wrong result please?

Thank you

Edited by pyTony: fixed formating

2
Contributors
1
Reply
2
Views
13 Years
Discussion Span
Last Post by nanosani
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.