Guest User

Untitled

a guest
Mar 7th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.93 KB | None | 0 0
  1. import java.util.Scanner;
  2. /**
  3.  * Calculates regression when given TPE count
  4.  *
  5.  * @author BigKicks
  6.  * @version 3/6/2020
  7.  */
  8. public class TPECalculator
  9. {
  10.     public static void main(String[] args)
  11.     {
  12.         //Variables & objects
  13.         int tpe = -1;
  14.         int year = -1;
  15.         String getInput;
  16.         boolean allCorrect = false;
  17.         int addTPE;
  18.         int menuPick;
  19.         Scanner get = new Scanner(System.in);
  20.         do
  21.         {
  22.             //Print menu
  23.             System.out.println("BigKicks's TPE Calculator\n");
  24.             System.out.println("Type \"1\" to calculate 1 year of regression.");
  25.             System.out.println("Type \"2\" to calculate multiple years WITHOUT added TPE per year.");
  26.             System.out.println("Type \"3\" to calculate multiple years WITH added TPE per year.");
  27.             System.out.println("Type \"Quit\" at any time to end this program.");
  28.             getInput = get.next();
  29.             //Menu select error trap
  30.             do
  31.             {
  32.                 while(!isNumber(getInput))
  33.                 {
  34.                     System.out.println("Invalid selection. Please try again.");
  35.                     getInput = get.next();
  36.                 }
  37.                 menuPick = Integer.parseInt(getInput);
  38.                 if(menuPick>3||menuPick<1)
  39.                 {
  40.                     System.out.println("Invalid selection. Please try again.");
  41.                     getInput = get.next();
  42.                 }
  43.                 if (isNumber(getInput)&&(menuPick<4&&menuPick>0))
  44.                     allCorrect = true;
  45.             }while(allCorrect!=true);
  46.             allCorrect = false;
  47.             //Execute menu choice
  48.             if(menuPick == 1)
  49.             {
  50.                 do
  51.                 {
  52.                     tpe = tpeTrap(getInput, get, tpe, allCorrect);
  53.                     year = yearTrap(getInput, get, year, allCorrect);
  54.                     if (year<8) //Unregressed
  55.                     {
  56.                         if (year == 0)
  57.                         {
  58.                             System.out.println("DSFL\t\t"+tpe+" TPE");
  59.                         }
  60.                         else
  61.                             System.out.println("Season "+year+"\t"+tpe+" TPE");
  62.                     }
  63.                     else //Regressed
  64.                     {
  65.                         tpe = (int)(tpe * getRegression(year));
  66.                         if (tpe < 150)
  67.                         {
  68.                             System.out.println("Your player has been auto-retired after season "+year+" with "+tpe+"TPE.");
  69.                             year = 16;
  70.                         }
  71.                         else
  72.                         {
  73.                             System.out.println("Season "+year+"\t"+tpe+" TPE");
  74.                         }
  75.                     }
  76.                     getInput = runTrap(getInput, get);
  77.                 }while(!getInput.equalsIgnoreCase("n"));
  78.             }
  79.             else if (menuPick == 2)
  80.             {
  81.                 do
  82.                 {
  83.                     tpe = tpeTrap(getInput, get, tpe, allCorrect);
  84.                     year = yearTrap(getInput, get, year, allCorrect);
  85.                     //Print DSFL year
  86.                     if (year==0)
  87.                     {
  88.                         System.out.println("DSFL\t\t"+tpe+" TPE");
  89.                         year++;
  90.                     }
  91.                     //Print seasons
  92.                     while (year<16)
  93.                     {
  94.                         if (year<8) //Unregressed
  95.                         {
  96.                             if (year == 0)
  97.                             {
  98.                                 System.out.println("DSFL\t\t"+tpe+" TPE");
  99.                                 year++;
  100.                             }
  101.                             else
  102.                             {
  103.                                 System.out.println("Season "+year+"\t"+tpe+" TPE");
  104.                                 year++;
  105.                             }
  106.                         }
  107.                         else //Regressed
  108.                         {
  109.                             tpe = (int)(tpe * getRegression(year));
  110.                             if (tpe < 150)
  111.                             {
  112.                                 System.out.println("Your player has been auto-retired after season "+year+" with "+tpe+"TPE.");
  113.                                 year = 16;
  114.                             }
  115.                             else
  116.                             {
  117.                                 System.out.println("Season "+year+"\t"+tpe+" TPE");
  118.                                 year++;
  119.                             }
  120.                         }
  121.                         allCorrect = false;
  122.                     }
  123.                     getInput = runTrap(getInput, get);
  124.                 }while(!getInput.equalsIgnoreCase("n"));
  125.             }
  126.             else
  127.             {
  128.                 do
  129.                 {
  130.                     tpe = tpeTrap(getInput, get, tpe, allCorrect);
  131.                     year = yearTrap(getInput, get, year, allCorrect);
  132.                     //Print DSFL year
  133.                     if (year==0)
  134.                     {
  135.                         System.out.println("DSFL\t\t"+tpe+" TPE");
  136.                         year++;
  137.                     }
  138.                     //Print seasons
  139.                     while (year<16)
  140.                     {
  141.                         System.out.print("Add TPE: ");
  142.                         getInput = get.next();
  143.                         do
  144.                         {
  145.                             while(!isNumber(getInput))
  146.                             {
  147.                                 System.out.println("Invalid value. Please try again.");
  148.                                 getInput = get.next();
  149.                             }
  150.                             addTPE = Integer.parseInt(getInput);
  151.                             if(addTPE<0)
  152.                             {
  153.                                 System.out.println("Invalid TPE amount. Please try again.");
  154.                                 getInput = get.next();
  155.                             }
  156.                             if (isNumber(getInput)&&addTPE>=0)
  157.                                 allCorrect = true;
  158.                         }while(allCorrect!=true);
  159.                         if (year<8) //Unregressed
  160.                         {
  161.                             tpe+=addTPE;
  162.                             System.out.println("Season "+year+"\t"+tpe+" TPE ("+addTPE+" added)");
  163.                             year++;
  164.                         }
  165.                         else //Regressed
  166.                         {
  167.                             tpe = (int)(tpe * getRegression(year));
  168.                             if (tpe < 150)
  169.                             {
  170.                                 System.out.println("Your player has been auto-retired after season "+year+" with "+tpe+"TPE.");
  171.                                 year = 16;
  172.                             }
  173.                             else
  174.                             {
  175.                                 tpe+=addTPE;
  176.                                 System.out.println("Season "+year+"\t"+tpe+" TPE ("+addTPE+" added)");
  177.                                 year++;
  178.                             }
  179.                         }
  180.                         addTPE = 0;
  181.                         allCorrect = false;
  182.                     }
  183.                     getInput = runTrap(getInput, get);
  184.                 }while(!getInput.equalsIgnoreCase("n"));
  185.             }
  186.             System.out.println("Would you like return to the menu? (y/n)");
  187.             getInput = get.next();
  188.             while(!getInput.equalsIgnoreCase("y")&&!getInput.equalsIgnoreCase("n"))
  189.             {
  190.                 if (getInput.equalsIgnoreCase("Quit"))
  191.                     System. exit(0);
  192.                 System.out.println("Invalid value. Please try again.");
  193.                 getInput = get.next();
  194.             }
  195.         }while(!getInput.equalsIgnoreCase("n"));
  196.     }
  197.     private static double getRegression(int year)
  198.     {
  199.         switch (year)
  200.         {
  201.             case (8): return .8;
  202.             case (9): return .75;
  203.             case (10): return .7;
  204.             case (11): return .6;
  205.             case (12): return .5;
  206.             case (13): return .4;
  207.             case (14): return .25;
  208.             case (15): return .25;
  209.             default: throw new IllegalArgumentException();
  210.         }
  211.     }
  212.     private static boolean isNumber(String input)
  213.     {
  214.         if (input.equalsIgnoreCase("Quit"))
  215.             System. exit(0);
  216.         try
  217.         {
  218.             Integer.parseInt(input);
  219.         }
  220.         catch(NumberFormatException ex)
  221.         {
  222.             return false;
  223.         }
  224.         return true;
  225.     }
  226.     private static int tpeTrap(String getInput, Scanner get, int tpe, boolean allCorrect)
  227.     {
  228.         //Prompt user for TPE
  229.         System.out.print("Enter TPE: ");
  230.         getInput = get.next();
  231.         //Error trap in case user entered a non-number or invalid number
  232.         do
  233.         {
  234.             while(!isNumber(getInput))
  235.             {
  236.                 System.out.println("Invalid value. Please try again.");
  237.                 getInput = get.next();
  238.             }
  239.             tpe = Integer.parseInt(getInput);
  240.             if(tpe<50)
  241.             {
  242.                 System.out.println("Invalid TPE amount. Please try again.");
  243.                 getInput = get.next();
  244.             }
  245.             if (isNumber(getInput)&&tpe>50)
  246.                 allCorrect = true;
  247.         }while(allCorrect!=true);
  248.         return tpe;
  249.     }
  250.     private static int yearTrap(String getInput, Scanner get, int year, boolean allCorrect)
  251.     {
  252.         //Prompt user for year
  253.         System.out.print("Enter season (if you're a rookie DSFL player, enter 0): ");
  254.         getInput = get.next();
  255.         //Error trap in case user entered a non-number or invalid number
  256.         do
  257.         {
  258.             while(!isNumber(getInput))
  259.             {
  260.                 System.out.println("Invalid value. Please try again.");
  261.                 getInput = get.next();
  262.             }
  263.             year = Integer.parseInt(getInput);
  264.             if(year>15||year<0)
  265.             {
  266.                 System.out.println("Invalid year. Please try again.");
  267.                 getInput = get.next();
  268.             }
  269.             if (isNumber(getInput)&&year<15&&year>=0)
  270.                 allCorrect = true;
  271.         }while(allCorrect!=true);
  272.         return year;
  273.     }
  274.     private static String runTrap(String getInput, Scanner get)
  275.     {
  276.         System.out.println("Would you like to run this program again? (y/n)");
  277.         getInput = get.next();
  278.         while(!getInput.equalsIgnoreCase("y")&&!getInput.equalsIgnoreCase("n"))
  279.         {
  280.             if (getInput.equalsIgnoreCase("Quit"))
  281.                 System. exit(0);
  282.             System.out.println("Invalid value. Please try again.");
  283.             getInput = get.next();
  284.         }
  285.         return getInput;
  286.     }
  287. }
Advertisement
Add Comment
Please, Sign In to add comment