Guest User

Untitled

a guest
Feb 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. /* Submission 2 task 1 by Stefan A. Brannfjell - Input
  2.  * The name Input might be a bit off. This class is pretty much the whole engine.
  3.  * It contains an easy configuration panel for you, in case you want to
  4.  * adjust point values, or translate the program to another language.
  5.  *
  6.  * Q: Why have you made an own method for every single Scanner listener variable?
  7.  *
  8.  * A: Because I still suck in java. I failed to find out a way to properly re-do
  9.  * a try {} code. So if you wrote "asd" instead of "123" in an integer Scanner
  10.  * listener, when you fetch the exception, you can simply call the same method
  11.  * again and ask user to redo the step. I bet this is a lousy way to solve this
  12.  * problem. Because you are not properly closing the old method before starting
  13.  * a new method. In bigger complicated and resourceful programs this will easily
  14.  * backfire. I tried to use "while" and "for" loops but with no luck.
  15.  */
  16.  
  17. import java.util.Scanner;
  18.  
  19. public class Input {
  20.     // SMALL CONFIG:
  21.     public static int winV = 3; // How many points do you get each win?
  22.     public static int drawV = 1; // How many points do you get each draw?
  23.     public static int lossV = 0; // How many points do you get each loss?
  24.  
  25.     /*
  26.      * Text messages:
  27.      * Change it to your desired language or whatever.
  28.      */
  29.  
  30.     // Error message that comes up when you write something else than numbers on integer related questions.
  31.     public static String err = "Feil: Det er bare tillatt og skrive tall. [For eksempel: 15].";
  32.  
  33.     // Asks the person who use the program for input regarding names, victories, draw, loss.
  34.     public static String mName = "Oppgi lagets navn: ";
  35.     public static String mVictories = "Oppgi antall seire: ";
  36.     public static String mDraw = "Oppgi antall uavgjort: ";
  37.     public static String mLoss = "Oppgi antall tap: ";
  38.  
  39.     // Table header names
  40.     public static String tTeam = "Lag";
  41.     public static String tTotal = "Kamper";
  42.     public static String tVictories = "Seire";
  43.     public static String tDraw = "Uavgjort";
  44.     public static String tLoss = "Tap";
  45.     public static String tPoints = "Poeng";
  46.     // OK, your DONE configurating.
  47.  
  48.     // Do not change below values.
  49.     public static String name;
  50.     public static int victories;
  51.     public static int draw;
  52.     public static int loss;
  53.  
  54.     // NAME
  55.     public static void name() {
  56.         Scanner input = new Scanner(System.in);
  57.         try {
  58.  
  59.             System.out.print(mName);
  60.  
  61.             name = input.next();
  62.         }
  63.         catch (Exception e) {
  64.             System.out.println("Error:");
  65.             name();
  66.         }
  67.     }
  68.  
  69.     // VICTORIES
  70.     public static void victories() {
  71.         Scanner input = new Scanner(System.in);
  72.         try {
  73.  
  74.             System.out.print(mVictories);
  75.  
  76.             victories = input.nextInt();
  77.         }
  78.         catch (Exception e) {
  79.             System.out.println(err);
  80.             victories();
  81.         }
  82.     }
  83.  
  84.     // DRAW
  85.     public static void draw() {
  86.         Scanner input = new Scanner(System.in);
  87.         try {
  88.  
  89.             System.out.print(mDraw);
  90.  
  91.             draw = input.nextInt();
  92.         }
  93.         catch (Exception e) {
  94.             System.out.println(err);
  95.             draw();
  96.         }
  97.     }
  98.  
  99.     // LOSS
  100.     public static void loss() {
  101.         Scanner input = new Scanner(System.in);
  102.         try {
  103.  
  104.             System.out.print(mLoss);
  105.  
  106.             loss = input.nextInt();
  107.         }
  108.         catch (Exception e) {
  109.             System.out.println(err);
  110.             loss();
  111.         }
  112.     }
  113.  
  114.     /* Generating the results table
  115.      * This method will generate the results, based on all input methods.
  116.      * This is placed into Input class because there is no point making a
  117.      * Generate class for such a small program as this.
  118.     */
  119.     public static void results() {
  120.         int total = (victories + draw + loss);
  121.         int points = ((victories * 3) + draw);
  122.         System.out.printf("\n\n%-15s%8s%6s%9s%5s%6s", tTeam, tTotal, tVictories, tDraw, tLoss, tPoints);
  123.         System.out.printf("\n%-15s%8d%6d%9d%5d%6d", name, total, victories, draw, loss, points);
  124.     }
  125. }
Add Comment
Please, Sign In to add comment