vendredi 14 septembre 2018

I don't understand why my manual income tax calculation is returning incorrect values

I am trying to do a manual income tax calculator and add a while statement to have the user re enter if the income is below zero. I am a complete newbie... What I am trying to do is take the different brackets to create a total tax due. For example the tax rate for any income 0-25000 is )%. The next bracket is 40000 where the tax is 5%. So, the program should say if your income is 40000 that your tax due is $750 ($0 for the first 25000 and 750 for the 5% of the 15000). I took a snippet of the code as the tax brackets go to 125000 and up. Thank you

package taxcalculator; import java.util.Scanner;

/** * * @author mtram */ public class Taxcalculator {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
  Scanner keyboard = new Scanner(System.in);

  System.out.println("Enter your income:");
  double income = keyboard.nextDouble();
  //while(income<0){
  //System.out.println("Please enter income above 0 ");
  //income = keyboard.nextDouble();

 double rate1 = 0.0;
 double rate2 = .05;
 double rate3 = .1;
 double rate4 = .15;
 double rate5 = .2;
 double rate6 = .25;
 double rate7 = .3;

 double rate1_limit = 25000;
 double rate2_limit =40000;
 double rate3_limit = 60000;
 double rate4_limit = 80000;
 double rate5_limit = 100000;
 double rate6_limit = 125000;

 double tax = 0;
  double tax1 = 0;
  double tax2 = 0;
   double tax3 = 0;
    double tax4 = 0;
        double tax5 = 0;
       double tax6 = 0;

 double totaltax = 0;

 if (income >=0)
 {
     if(income<=25000)
     {
         tax = rate1_limit * rate1;
         totaltax = tax;
     }
     else if (income > 25000 && income <= 40000)
     {
         tax = rate1_limit * rate1;
         tax1 = (income - rate1_limit) * rate2;
         totaltax = tax + tax1;
     }
     else if (income > 40000 && income <= 60000)
     {




         System.out.println("Your tax due is $" + totaltax);

Aucun commentaire:

Enregistrer un commentaire