Guest User

Regression Calculator 1.0.1

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