eranseg

IRS

Jul 24th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class IRS {
  4.     public static void main(String[] args) {
  5.         Scanner s = new Scanner(System.in);
  6.         int salary, numOfChild;
  7.         boolean isAdult, isNearGulliver, isParent;
  8.         float tax;
  9.         System.out.println("Please enter your payroll: ");
  10.         salary = s.nextInt();
  11.         // Calculating the taxes in accordance with the salary
  12.         switch(salary / 5000) {
  13.             case 0:
  14.                 tax = 0;
  15.                 break;
  16.             case 1:
  17.                 tax = salary * 0.1f;
  18.                 break;
  19.             case 2:
  20.                 tax = salary * 0.35f;
  21.                 break;
  22.             default:
  23.                 tax = salary * 0.5f;
  24.                 break;
  25.         }
  26.         System.out.println("Please enter 'true' if you are over 18 years old, or 'false' otherwise: ");
  27.         isAdult = s.nextBoolean();
  28.         System.out.println("Please enter 'true' if you have children, or 'false' otherwise: ");
  29.         isParent = s.nextBoolean();
  30.         // If not an adult and not a parent
  31.         if(!(isAdult || isParent)) {
  32.             tax *= 0.5f;
  33.         } else {
  34.             System.out.println("Please enter 'true' if you live near Gulliver, or 'false' otherwise: ");
  35.             isNearGulliver = s.nextBoolean();
  36.             if(isNearGulliver && salary < 10000) {
  37.                 tax -= 400; // Calculating discount in taxes
  38.             }
  39.             if(isParent) {
  40.                 System.out.println("Please enter the number of children you have: ");
  41.                 numOfChild = s.nextInt();
  42.                 tax = numOfChild >= 3 ? tax - 900 : tax - (300 * numOfChild); // Calculating discount in taxes
  43.             }
  44.         }
  45.         if(tax >= 0) {
  46.             System.out.println("You have to pay " + tax + " ILS to the IRS.");
  47.         } else {
  48.             System.out.println("IRS should pay you " + (-tax) + "ILS!"); // Negative taxes
  49.         }
  50.     }
  51. }
Add Comment
Please, Sign In to add comment