Как включить буферизованного писателя в мою игру со случайными догадками? - PullRequest
0 голосов
/ 20 ноября 2018

У меня есть задача, где мне нужно включить буферизованный писатель в мой Java-код, чтобы восстановить догадки в случае сбоя программы. Например, программа спросит: «Вы хотите восстановить те же догадки, которые у вас были?».

Я немного растерялся, что делать. Любые предложения или помощь будет принята с благодарностью.

import java.util.*;

public class Guess{

public static void main(String[] args){

    Scanner scan = new Scanner(System.in);
    String playAgain = "";


    do { 
    int randomTarget = randomNumberGenerator();
    int userInput = 0;
    System.out.println("Welcome to the random number generator game!");
    System.out.println("Enter a number between 1 through 10:");
    int count = 0;


    while (userInput != randomTarget){    
        try{
        userInput = scan.nextInt();
        }catch(Exception e){
            System.out.println("Invalid type.");
            count++;
            String s = scan.next();  
            System.out.println(s + " is an invalid input. Try again");
            continue;
        } 
        if (userInput > randomTarget){
            count++;
            System.out.println ("Number too high!");          
        }else if (userInput < randomTarget){
            count++;
            System.out.println("Number too low");   
        }else{  
        System.out.println("Congratulations, you guessed correctly!");
        count++;
        System.out.println("It took you: " + count + " tries!");
        playAgainQ();
        try {
        playAgain = scan.next();
        } catch (Exception e) {
            System.out.println(playAgain + " is an invalid input. Try again");
            continue;
        }

        }


    }
    } while (playAgain.equalsIgnoreCase("y"));
    System.out.println("Thanks for playing. Goodbye!");

}
static void playAgainQ() {
      System.out.println("Do you want to play again? Type y for yes.");
}
static int randomNumberGenerator() {
    Random randomNumber = new Random();
    int randomTarget = (randomNumber.nextInt(10) + 1);
    return randomTarget;
 }

 }
...