Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.InputMismatchException;
- import java.util.Scanner;
- public class lotto {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- println("Lottery Program");
- int[] guessState = {};
- while (true) {
- guessState = menu(sc, guessState);
- }
- }
- static int[] menu(Scanner sc, int[] oldGuess) {
- boolean isFirstRound = oldGuess.length == 0;
- String prompt = "\nSelect 'n for choosing new numbers'";
- if (!isFirstRound) {
- prompt += ", 's' for using the same numbers";
- }
- prompt += "\nand 'q' to quit: ";
- print(prompt);
- String input = sc.next();
- switch (input) {
- case "n": {
- return playWithNew();
- }
- case "s": {
- if (!isFirstRound) {
- return playWithSame(oldGuess);
- }
- }
- case "q": {
- quit(sc);
- }
- default: {
- println("Invalid input.");
- return oldGuess;
- }
- }
- }
- static void print(String input) {
- System.out.print(input);
- }
- static void println(String input) {
- System.out.println(input);
- }
- static int[] playWithSame(int[] oldGuess) {
- return oldGuess;
- }
- static int[] playWithNew() {
- return null;
- }
- static void quit(Scanner sc) {
- sc.close();
- System.exit(0);
- }
- static int[] getLotteryNumbers(int amount) {
- return null;
- }
- static boolean hasWon(int[] guess, int[] draw) {
- return true;
- }
- static boolean isNumberInArray(int number, int[] arr) {
- return false;
- }
- // Position für Prompt bei falschem Input?
- static int getSafeInt(Scanner sc) {
- while (true) {
- try {
- int number = sc.nextInt();
- return number;
- } catch (InputMismatchException exception) {
- sc.nextLine();
- System.out.println("Invalid input. Please input a number between 1 and 49.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement