Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Calculates regression when given TPE count
- *
- * @author BigKicks
- * @version 1.0.0 3/6/2020
- * @version 1.0.1 3/12/2020
- */
- public class TPECalculator
- {
- public static void main(String[] args)
- {
- //Variables & objects
- int tpe = -1;
- int year = -1;
- String getInput;
- boolean allCorrect = false;
- int addTPE;
- int menuPick;
- Scanner get = new Scanner(System.in);
- do
- {
- //Print menu
- System.out.println("BigKicks's TPE Calculator\n");
- System.out.println("Type \"1\" to calculate 1 year of regression.");
- System.out.println("Type \"2\" to calculate multiple years WITHOUT added TPE per year.");
- System.out.println("Type \"3\" to calculate multiple years WITH added TPE per year.");
- System.out.println("Type \"Quit\" at any time to end this program.");
- getInput = get.next();
- //Menu select error trap
- do
- {
- while(!isNumber(getInput))
- {
- System.out.println("Invalid selection. Please try again.");
- getInput = get.next();
- }
- menuPick = Integer.parseInt(getInput);
- if(menuPick>3||menuPick<1)
- {
- System.out.println("Invalid selection. Please try again.");
- getInput = get.next();
- }
- if (isNumber(getInput)&&(menuPick<4&&menuPick>0))
- allCorrect = true;
- }while(allCorrect!=true);
- allCorrect = false;
- //Execute menu choice
- if(menuPick == 1)
- {
- do
- {
- tpe = tpeTrap(getInput, get, tpe, allCorrect);
- year = yearTrap(getInput, get, year, allCorrect);
- if (year<8) //Unregressed
- {
- if (year == 0)
- {
- System.out.println("DSFL\t\t"+tpe+" TPE");
- }
- else
- System.out.println("Season "+year+"\t"+tpe+" TPE");
- }
- else //Regressed
- {
- tpe = (int)(tpe * getRegression(year));
- if (tpe < 150)
- {
- System.out.println("Your player has been auto-retired after season "+year+" with "+tpe+" TPE.");
- year = 16;
- }
- else
- {
- System.out.println("Season "+year+"\t"+tpe+" TPE");
- }
- }
- getInput = runTrap(getInput, get);
- }while(!getInput.equalsIgnoreCase("n"));
- }
- else if (menuPick == 2)
- {
- do
- {
- tpe = tpeTrap(getInput, get, tpe, allCorrect);
- year = yearTrap(getInput, get, year, allCorrect);
- //Print DSFL year
- if (year==0)
- {
- System.out.println("DSFL\t\t"+tpe+" TPE");
- year++;
- }
- //Print seasons
- while (year<16)
- {
- if (year<8) //Unregressed
- {
- if (year == 0)
- {
- System.out.println("DSFL\t\t"+tpe+" TPE");
- year++;
- }
- else
- {
- System.out.println("Season "+year+"\t"+tpe+" TPE");
- year++;
- }
- }
- else //Regressed
- {
- tpe = (int)(tpe * getRegression(year));
- if (tpe < 150)
- {
- System.out.println("Your player has been auto-retired after season "+(year-1)+" with "+tpe+" TPE.");
- year = 16;
- }
- else
- {
- System.out.println("Season "+year+"\t"+tpe+" TPE");
- year++;
- }
- }
- allCorrect = false;
- }
- getInput = runTrap(getInput, get);
- }while(!getInput.equalsIgnoreCase("n"));
- }
- else
- {
- do
- {
- tpe = tpeTrap(getInput, get, tpe, allCorrect);
- year = yearTrap(getInput, get, year, allCorrect);
- //Print DSFL year
- if (year==0)
- {
- System.out.println("DSFL\t\t"+tpe+" TPE");
- year++;
- }
- //Print seasons
- while (year<16)
- {
- System.out.print("Add TPE: ");
- getInput = get.next();
- do
- {
- while(!isNumber(getInput))
- {
- System.out.println("Invalid value. Please try again.");
- getInput = get.next();
- }
- addTPE = Integer.parseInt(getInput);
- if(addTPE<0)
- {
- System.out.println("Invalid TPE amount. Please try again.");
- getInput = get.next();
- }
- if (isNumber(getInput)&&addTPE>=0)
- allCorrect = true;
- }while(allCorrect!=true);
- if (year<8) //Unregressed
- {
- System.out.println("Season "+year+" BEFORE added TPE\t"+tpe+" TPE");
- tpe+=addTPE;
- System.out.println("Season "+year+" AFTER added TPE\t"+tpe+" TPE ("+addTPE+" added)");
- year++;
- }
- else //Regressed
- {
- tpe = (int)(tpe * getRegression(year));
- if (tpe < 150)
- {
- System.out.println("Your player has been auto-retired after season "+(year-1)+" with "+tpe+" TPE.");
- year = 16;
- }
- else
- {
- System.out.println("Season "+year+" BEFORE added TPE\t"+tpe);
- tpe+=addTPE;
- System.out.println("Season "+year+" AFTER added TPE\t"+tpe+" TPE ("+addTPE+" added)");
- year++;
- }
- }
- addTPE = 0;
- allCorrect = false;
- }
- getInput = runTrap(getInput, get);
- }while(!getInput.equalsIgnoreCase("n"));
- }
- System.out.println("Would you like return to the menu? (y/n)");
- getInput = get.next();
- while(!getInput.equalsIgnoreCase("y")&&!getInput.equalsIgnoreCase("n"))
- {
- if (getInput.equalsIgnoreCase("Quit"))
- System. exit(0);
- System.out.println("Invalid value. Please try again.");
- getInput = get.next();
- }
- }while(!getInput.equalsIgnoreCase("n"));
- }
- private static double getRegression(int year)
- {
- switch (year)
- {
- case (8): return .8;
- case (9): return .75;
- case (10): return .7;
- case (11): return .6;
- case (12): return .5;
- case (13): return .4;
- case (14): return .25;
- case (15): return .25;
- default: throw new IllegalArgumentException();
- }
- }
- private static boolean isNumber(String input)
- {
- if (input.equalsIgnoreCase("Quit"))
- System. exit(0);
- try
- {
- Integer.parseInt(input);
- }
- catch(NumberFormatException ex)
- {
- return false;
- }
- return true;
- }
- private static int tpeTrap(String getInput, Scanner get, int tpe, boolean allCorrect)
- {
- //Prompt user for TPE
- System.out.print("Enter TPE: ");
- getInput = get.next();
- //Error trap in case user entered a non-number or invalid number
- do
- {
- while(!isNumber(getInput))
- {
- System.out.println("Invalid value. Please try again.");
- getInput = get.next();
- }
- tpe = Integer.parseInt(getInput);
- if(tpe<50)
- {
- System.out.println("Invalid TPE amount. Please try again.");
- getInput = get.next();
- }
- if (isNumber(getInput)&&tpe>50)
- allCorrect = true;
- }while(allCorrect!=true);
- return tpe;
- }
- private static int yearTrap(String getInput, Scanner get, int year, boolean allCorrect)
- {
- //Prompt user for year
- System.out.print("Enter season (if you're a rookie DSFL player, enter 0): ");
- getInput = get.next();
- //Error trap in case user entered a non-number or invalid number
- do
- {
- while(!isNumber(getInput))
- {
- System.out.println("Invalid value. Please try again.");
- getInput = get.next();
- }
- year = Integer.parseInt(getInput);
- if(year>15||year<0)
- {
- System.out.println("Invalid year. Please try again.");
- getInput = get.next();
- }
- if (isNumber(getInput)&&year<15&&year>=0)
- allCorrect = true;
- }while(allCorrect!=true);
- return year;
- }
- private static String runTrap(String getInput, Scanner get)
- {
- System.out.println("Would you like to run this program again? (y/n)");
- getInput = get.next();
- while(!getInput.equalsIgnoreCase("y")&&!getInput.equalsIgnoreCase("n"))
- {
- if (getInput.equalsIgnoreCase("Quit"))
- System. exit(0);
- System.out.println("Invalid value. Please try again.");
- getInput = get.next();
- }
- return getInput;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment