×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Parker Huhta
Added: Sep 7, 2017 11:33 PM
Views: 5
Tags: no tags
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Project1_Explore {
  5.    
  6.         public static void main(String[] args)
  7.         {
  8.            
  9.         // declare variables
  10.         int customerID;
  11.         double totalEarnings = 0.0;
  12.         double federalTaxesWH = 0.0;
  13.         double stateTaxWH = 0.0;
  14.         double deductions = 0.0;
  15.         double taxableIncome = 0.0;
  16.         double federalTax = 0.0;
  17.         double stateRefund = 0.0;
  18.         double stateTax = 0.0;
  19.         double federalRefund = 0.0;
  20.  
  21.         // Create a Scanner input object
  22.  
  23.         Scanner input = new Scanner( System.in );
  24.        
  25.         //Create output string
  26.        
  27.         String outputString = new String();
  28.         outputString = "Cust.                   Taxable Federal State Federal State Federal State \n" +
  29.                        " ID   Income Deductions Income    Tax    Tax    W/H    W/H  Refund  Refund\n" +
  30.                        "===== ====== ========== ======= ======= ===== ======= ===== ======= ======\n";
  31.                       // "%5d   $%6.0f  $%.0f     $%.0f  $%.0f  $%.0f  $%.0f  $%.0f   $%.0f   $%.0f\n"
  32.        
  33.         // Begin first customer
  34.  
  35.         System.out.println( "Welcome to the Tax Account Program!\n"
  36.         + "Begin by entering the Customer ID: " );
  37.      
  38.        
  39.         // Get first Customer ID
  40.         customerID = input.nextInt();
  41.  
  42.         while( customerID != -1 )
  43.         {
  44.             // Get income and withholding information
  45.  
  46.         System.out.println( "Enter Total Earnings for customer: " );
  47.         totalEarnings = input.nextFloat();
  48.        
  49.        
  50.         System.out.println( "Enter Federal Taxes Withheld: " );
  51.          federalTaxesWH = input.nextFloat();
  52.        
  53.         System.out.println( "Enter State Taxes Withheld: " );
  54.         stateTaxWH = input.nextFloat();
  55.        
  56.  
  57.         System.out.println( "Enter Deductions: " );
  58.         deductions = input.nextFloat();
  59.        
  60.        
  61.             // Calculate taxes due/refunds
  62.  
  63.             taxableIncome = totalEarnings - deductions;
  64.            
  65.             if( taxableIncome >= 0 && taxableIncome <= 10000 )
  66.             {
  67.                federalTax = 0.0;
  68.             }
  69.            
  70.             if( taxableIncome >= 10001 && taxableIncome <= 20000 )
  71.             {
  72.                federalTax = ( taxableIncome - 10000) * (.15 );
  73.             }
  74.  
  75.             if( taxableIncome >= 20001 && taxableIncome <= 40000 )
  76.             {
  77.                federalTax = 1500 + ( taxableIncome - 20000 ) * ( .2 );
  78.             }
  79.              
  80.             if( taxableIncome > 40000 )
  81.             {
  82.                federalTax = 5500 + ( taxableIncome - 40000 ) * ( .3 );
  83.             }
  84.            
  85.             stateTax = ( federalTax * .07 );
  86.            
  87.             federalRefund = federalTaxesWH - federalTax;
  88.            
  89.             stateRefund = stateTaxWH - stateTax;
  90.            
  91.             //create strings for output string formatting
  92.            
  93.            
  94.             String taxableIncomeCur = String.format("$%.0f", taxableIncome);
  95.             String federalTaxCur = String.format("$%.0f", federalTax);
  96.             String stateTaxCur = String.format("$%.0f", stateTax);
  97.             String federalRefundCur = String.format("$%.0f", federalRefund);
  98.             String stateRefundCur = String.format("$%.0f", stateRefund);
  99.             String totalEarningsCur = String.format("$%.0f", totalEarnings );
  100.             String federalTaxesWHCur = String.format("$%.0f", federalTaxesWH );
  101.             String stateTaxWHCur = String.format("$%.0f", stateTaxWH );
  102.             String deductionsCur = String.format("$%.0f", deductions);
  103.            
  104.             //format dataString to add to outputString
  105.             String dataString= String.format("%-5d %6s %7s    "
  106.                 + "%6s  %6s  %4s  %6s  %5s   %5s  %5s \n", customerID,    
  107.                 totalEarningsCur, deductionsCur,
  108.                 taxableIncomeCur, federalTaxCur, stateTaxCur, federalTaxesWHCur,
  109.                 stateTaxWHCur, federalRefundCur, stateRefundCur);
  110.             // Add data to output String
  111.            
  112.             outputString = outputString + dataString;
  113.  
  114.             // Get next Customer ID
  115.            
  116.             System.out.println("Enter next Customer ID or press -1 "
  117.                     + "to print data:");
  118.             customerID = input.nextInt();
  119.  
  120.         }
  121.  
  122.         // Print out table of data and end program
  123.        
  124.         System.out.print(outputString);
  125.        
  126.        
  127.    }
  128.        
  129. }