Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Submission 2 task 1 by Stefan A. Brannfjell - Input
- * The name Input might be a bit off. This class is pretty much the whole engine.
- * It contains an easy configuration panel for you, in case you want to
- * adjust point values, or translate the program to another language.
- *
- * Q: Why have you made an own method for every single Scanner listener variable?
- *
- * A: Because I still suck in java. I failed to find out a way to properly re-do
- * a try {} code. So if you wrote "asd" instead of "123" in an integer Scanner
- * listener, when you fetch the exception, you can simply call the same method
- * again and ask user to redo the step. I bet this is a lousy way to solve this
- * problem. Because you are not properly closing the old method before starting
- * a new method. In bigger complicated and resourceful programs this will easily
- * backfire. I tried to use "while" and "for" loops but with no luck.
- */
- import java.util.Scanner;
- public class Input {
- // SMALL CONFIG:
- public static int winV = 3; // How many points do you get each win?
- public static int drawV = 1; // How many points do you get each draw?
- public static int lossV = 0; // How many points do you get each loss?
- /*
- * Text messages:
- * Change it to your desired language or whatever.
- */
- // Error message that comes up when you write something else than numbers on integer related questions.
- public static String err = "Feil: Det er bare tillatt og skrive tall. [For eksempel: 15].";
- // Asks the person who use the program for input regarding names, victories, draw, loss.
- public static String mName = "Oppgi lagets navn: ";
- public static String mVictories = "Oppgi antall seire: ";
- public static String mDraw = "Oppgi antall uavgjort: ";
- public static String mLoss = "Oppgi antall tap: ";
- // Table header names
- public static String tTeam = "Lag";
- public static String tTotal = "Kamper";
- public static String tVictories = "Seire";
- public static String tDraw = "Uavgjort";
- public static String tLoss = "Tap";
- public static String tPoints = "Poeng";
- // OK, your DONE configurating.
- // Do not change below values.
- public static String name;
- public static int victories;
- public static int draw;
- public static int loss;
- // NAME
- public static void name() {
- Scanner input = new Scanner(System.in);
- try {
- System.out.print(mName);
- name = input.next();
- }
- catch (Exception e) {
- System.out.println("Error:");
- name();
- }
- }
- // VICTORIES
- public static void victories() {
- Scanner input = new Scanner(System.in);
- try {
- System.out.print(mVictories);
- victories = input.nextInt();
- }
- catch (Exception e) {
- System.out.println(err);
- victories();
- }
- }
- // DRAW
- public static void draw() {
- Scanner input = new Scanner(System.in);
- try {
- System.out.print(mDraw);
- draw = input.nextInt();
- }
- catch (Exception e) {
- System.out.println(err);
- draw();
- }
- }
- // LOSS
- public static void loss() {
- Scanner input = new Scanner(System.in);
- try {
- System.out.print(mLoss);
- loss = input.nextInt();
- }
- catch (Exception e) {
- System.out.println(err);
- loss();
- }
- }
- /* Generating the results table
- * This method will generate the results, based on all input methods.
- * This is placed into Input class because there is no point making a
- * Generate class for such a small program as this.
- */
- public static void results() {
- int total = (victories + draw + loss);
- int points = ((victories * 3) + draw);
- System.out.printf("\n\n%-15s%8s%6s%9s%5s%6s", tTeam, tTotal, tVictories, tDraw, tLoss, tPoints);
- System.out.printf("\n%-15s%8d%6d%9d%5d%6d", name, total, victories, draw, loss, points);
- }
- }
Add Comment
Please, Sign In to add comment