jwrbg

SocialSecurityCalc

Feb 14th, 2020
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com;
  2.  
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class SocialSecurityCalculator
  7. {
  8.   public static void main(String[] args)
  9.   {
  10.     final int BASE_TAX = 3000;
  11.     Scanner scanner = new Scanner(System.in);
  12.     double salary = scanner.nextDouble();
  13.     int age = scanner.nextInt();
  14.     double taxPerUser;
  15.     double taxPerCompany;
  16.     double totalTax;
  17.  
  18.     if (salary <= BASE_TAX) {
  19.       double[] allTaxes = calculateTaxForSalaryToThreeThousand(age, salary);
  20.       totalTax = allTaxes[0];
  21.       taxPerCompany = allTaxes[1];
  22.       taxPerUser = allTaxes[2];
  23.  
  24.     }
  25.     else {
  26.       double salaryPerTax = salary - BASE_TAX;
  27.       taxPerCompany = salaryPerTax * 0.2;
  28.       taxPerUser = salaryPerTax * 0.2;
  29.       totalTax = calculateTaxForSalaryToThreeThousand(age, BASE_TAX)[0] + taxPerCompany + taxPerUser;
  30.  
  31.     }
  32.     System.out.printf("Total tax is %.2f.%nTax for employeer is %.2f.%nTax for employee is %.2f.", totalTax, taxPerCompany, taxPerUser);
  33.  
  34.   }
  35.  
  36.   static double[] calculateTaxForSalaryToThreeThousand(int age, double salary)
  37.   {
  38.     double taxPerUser;
  39.     double taxPerCompany;
  40.     double totalTax;
  41.     if (age <= 55) {
  42.       taxPerUser = salary * 0.2;
  43.       taxPerCompany = salary * 0.17;
  44.     }
  45.     else if (age > 55 && age <= 60) {
  46.       taxPerUser = salary * 0.13;
  47.       taxPerCompany = salary * 0.13;
  48.  
  49.     }
  50.     else if (age > 60 && age <= 65) {
  51.       taxPerUser = salary * 0.075;
  52.       taxPerCompany = salary * 0.09;
  53.     }
  54.     else {
  55.       taxPerUser = salary * 0.05;
  56.       taxPerCompany = salary * 0.075;
  57.     }
  58.     totalTax = taxPerCompany + taxPerUser;
  59.     double[] result = {totalTax, taxPerCompany, taxPerUser};
  60.     return result;
  61.   }
  62. }
RAW Paste Data