SHARE
TWEET

lotto.java

a guest Dec 12th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.InputMismatchException;
  2. import java.util.Scanner;
  3.  
  4. public class lotto {
  5.  
  6.   public static void main(String[] args) {
  7.     Scanner sc = new Scanner(System.in);
  8.    
  9.     println("Lottery Program");
  10.  
  11.     int[] guessState = {};
  12.  
  13.     while (true) {
  14.       guessState = menu(sc, guessState);
  15.     }
  16.   }
  17.  
  18.   static int[] menu(Scanner sc, int[] oldGuess) {
  19.     boolean isFirstRound = oldGuess.length == 0;
  20.  
  21.     String prompt = "\nSelect 'n for choosing new numbers'";
  22.  
  23.     if (!isFirstRound) {
  24.       prompt += ", 's' for using the same numbers";
  25.     }
  26.  
  27.     prompt += "\nand 'q' to quit: ";
  28.  
  29.     print(prompt);
  30.  
  31.     String input = sc.next();
  32.  
  33.     switch (input) {
  34.       case "n": {
  35.         return playWithNew();
  36.       }
  37.       case "s": {
  38.         if (!isFirstRound) {
  39.           return playWithSame(oldGuess);
  40.         }
  41.       }
  42.       case "q": {
  43.         quit(sc);
  44.       }
  45.       default: {
  46.         println("Invalid input.");
  47.         return oldGuess;
  48.       }
  49.     }
  50.   }
  51.  
  52.   static void print(String input) {
  53.     System.out.print(input);
  54.   }
  55.  
  56.   static void println(String input) {
  57.     System.out.println(input);
  58.   }
  59.  
  60.   static int[] playWithSame(int[] oldGuess) {
  61.     return oldGuess;
  62.   }
  63.  
  64.   static int[] playWithNew() {
  65.     return null;
  66.   }
  67.  
  68.   static void quit(Scanner sc) {
  69.     sc.close();
  70.     System.exit(0);
  71.   }
  72.  
  73.   static int[] getLotteryNumbers(int amount) {
  74.     return null;
  75.   }
  76.  
  77.   static boolean hasWon(int[] guess, int[] draw) {
  78.     return true;
  79.   }
  80.  
  81.   static boolean isNumberInArray(int number, int[] arr) {
  82.     return false;
  83.   }
  84.  
  85.   // Position für Prompt bei falschem Input?
  86.   static int getSafeInt(Scanner sc) {
  87.     while (true) {
  88.       try {
  89.         int number = sc.nextInt();
  90.         return number;
  91.       } catch (InputMismatchException exception) {
  92.         sc.nextLine();
  93.         System.out.println("Invalid input. Please input a number between 1 and 49.");
  94.       }
  95.     }
  96.   }
  97. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top