algorithm - Calculating tax owed with thresholds and rates in java -


for part of revenue program making assignment school have calculate number total tax owed citizen. given in text file number of thresholds, threshold value, , rate @ each threshold. example

threshold   rate $15,000 15% $29,000 20% $50,000 25% 

a citizen net income $55,000 pay: $15,000*0%+$14,000*15%+$21,000*20%+$5,000*25% = $7,550

i have started method here

private void computetaxowed(citizen cit, taxschedule sked){      double netincome = cit.getnetincome();     double tottaxpaid = cit.gettottaxpaid();      int levels = sked.getnumlevels();     double[] threshold = sked.getthreshold();     double[] rate = sked.getrate();      double taxowd = 0;      for(int = levels; i>0; i--){         taxowd = ((netincome-threshold[i])*rate[i]);     } 

i know not give correct output , can't figure out how make algorithm work. if extract values of both arrays , save them each individual variable right output think messy , not best way it.

any ideas appreciated!

class main {      public static void main(string[] args) {          double netincome = 55000;          int levels = 3;         double[] threshold = {0, 15000, 29000, 50000};         double[] rate = {0, 15,20,25};          double taxowd = 0;          double taxableincome = 0;         double netincomeleft = netincome;          (int = levels; > 0; i--) {             taxableincome = netincomeleft - threshold[i];             taxowd += taxableincome * (rate[i]/100);             netincomeleft = threshold[i];         }         system.out.println("taxowd " + taxowd);     } } 

or in more compact fashion:

        (int = levels; > 0; i--) {             taxowd += ((netincome - threshold[i]) * (rate[i]/100));             netincome = threshold[i];         } 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -