Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. //Jacob Baker
  2. //Lab-03
  3. //StartA.java
  4. //AKA "An Even 'SLICKER' Method Than the Methods Used in Parts B & C"   :)
  5. public class StartA {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.  
  10.         // test methods here:
  11. //      Magic.println(computeTaxes(500000));
  12.         int userIncome = StartD.promptUserGetInt("Enter your Taxable Income");
  13.         Magic.println("You owe this much in federal income taxes: $" + computeTaxes(userIncome));
  14.  
  15.     }// end main
  16.    
  17.    
  18.     //let "double userIncome" take place of the parameter name "taxableIncome"
  19.     public static double computeTaxes(double userIncome) {
  20.         // two arrays whose positions correspond in Marginal Tax Rate and Taxable Income
  21.         double[] taxRate = { 0.10, 0.15, 0.25, 0.28, 0.33, 0.35, 0.396 };
  22.         double[] taxableIncome = { 9275.00, 37650.00, 91150.00, 190150.00, 413350.00, 415050.00, 415050.01 };
  23.         double totalTaxes = 0;
  24.         double lastTaxes = 0;
  25.         //this boolean is used to break the main loop from inside the nested loop
  26.         boolean breakMainLoop = true;
  27.        
  28.         //condition specific for userIncome > taxableIncome[6]
  29.         if (userIncome >= taxableIncome[6]) {
  30.             for (int i = 0; i < taxableIncome.length && breakMainLoop == true; i++) {
  31.  
  32.                 if (i == 6) {
  33.                     lastTaxes += (taxRate[i] * (userIncome - taxableIncome[i]));
  34.                     totalTaxes += lastTaxes;
  35.                     Magic.println(totalTaxes);
  36.  
  37.                     breakMainLoop = false;
  38.                 } else if (i > 0) {
  39.                     totalTaxes += (taxRate[i] * (taxableIncome[i] - taxableIncome[i - 1]));
  40.                 } else if (i == 0) {
  41.                     totalTaxes += taxRate[i] * taxableIncome[i];
  42.                 }
  43.             }
  44.         } else {
  45.             //conditions for any userIncome that is less than taxableIncome[6]
  46.             //this loop runs the taxableIncome array elements into the corresponding "if" statement
  47.             for (int i = 0; i < taxableIncome.length && breakMainLoop == true; i++) {
  48.                 if (userIncome >= taxableIncome[i]) {
  49.                     //this loop runs numbers through corresponding conditionals to determine "totalTaxes"
  50.                     for (int j = 0; userIncome >= taxableIncome[j]; j++) {
  51.                         if (j > 0) {
  52.                             //follows the formula given in the example of the lab instructions
  53.                             totalTaxes += (taxRate[j] * (taxableIncome[j] - taxableIncome[j - 1]));
  54.                            
  55.                             //checks to see if the next element in the array greater than "userIncome"
  56.                             if (userIncome < taxableIncome[j + 1]) {
  57.                                 //if true, follow the last operation found in the formula example of the lab instructions through this equation
  58.                                 lastTaxes += taxRate[j + 1] * (userIncome - taxableIncome[j]);
  59.                                 //add it on to the taxes totaled from previous positions
  60.                                 totalTaxes += lastTaxes;
  61.                                 Magic.println(totalTaxes);
  62.                                
  63.                                 //if the next element in the array is greater, then break the main loop
  64.                                 breakMainLoop = false;
  65.                             }
  66.  
  67.                         } else if (j == 0) {
  68.                             //specific for taxable income <= 9752.00
  69.                             //value is saved in "totalTaxes" and is run back through the loop to carry on thru "j > 0"
  70.                             totalTaxes += taxRate[j] * taxableIncome[j];
  71.  
  72.                         }
  73.                     }
  74.                 } else if (userIncome <= 9725) {
  75.                     totalTaxes += taxRate[0] * userIncome;
  76.  
  77.                     breakMainLoop = false;
  78.                 }
  79.             }
  80.  
  81.         }
  82.         return totalTaxes;
  83.     }
  84.  
  85. }// end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement