Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi-Lo Game (with Dice) In this homework, you will be writing a program, which re

ID: 3864687 • Letter: H

Question

Hi-Lo Game (with Dice) In this homework, you will be writing a program, which repeatedly asks the user if the next roll will be higher or lower than the last dice roll. You will continually play until the user types quit on a line by itself. The game will remember how many times you were successful and how many times you tried and report the ratio of success to tries after the user quits. In addition, the game will maintain persistence: remembering you and how many times you've played even after exiting (by maintaining a file). You will need to ask the user for their user name prior to playing and use that to record their results in a file. If the user has played before, the number of successful tries and the number of tries is in a file named after the user with a .txt extension. If not, we start at zero for that user. Once the user quits, you'll need to save the new results into the correct file. Your dialog should be clear each time you ask for something what you are asking for and output the result. Logic reading/determining the hi/lo/quit Logic providing the dice rolls Logic providing the persistence which includes: a. Determine if the file exists b. Opening the file, reading the number correct and the number of tries (each on their own line) c. Once finished, rewriting the file so that it contains current data The logic providing the rest of the result (managing the play, keeping score, calculations) Name your program: DiceHILO.java

Explanation / Answer

import java.util.Random;
import java.util.Scanner;
public class HiLo
{
   public static void main (String[] args)
   {
       //declare variables
       final int MAX = 10;
       int answer, guess;
       int numberOfTries = 0 ;
       String again;

       Scanner Keyboard = new Scanner(System.in);

       do

       {
           System.out.print (" I'm thinking of a number between 0 and "
           + MAX + ". Guess what it is: ");
           guess = Keyboard.nextInt();
           //guess
           Random generator = new Random();
           answer = generator.nextInt(MAX) +1;

           if (guess > 10)
           {
           System.out.println ("ERROR – Your guess is out of the range 0 to 10.");
           }
           if (guess < 0)
           {
       System.out.println ("ERROR – Your guess is out of the range 0 to 10.");
           }

           while (guess != answer )
           {

           if (guess > answer )
           {
           System.out.println ("You guessed too high! Try again:");
           guess = Keyboard.nextInt();
           }

           if (guess < answer )
           {
           System.out.println ("Too Low! Try again:");
           guess = Keyboard.nextInt();
           }

           numberOfTries=numberOfTries+1;

           }
          
           if ( guess == answer)
           {
           numberOfTries += 1;
           System.out.println ("YOU WIN!");
           System.out.println("It took you " + numberOfTries + " tries!") ;
           System.out.println();
           System.out.print( "Do you want to play again(Y/N)?");
           }


           Keyboard.nextLine(); // skip over enter key
           again = Keyboard.nextLine();

   numberOfTries=0;
       } while (again.equalsIgnoreCase ("Y") );

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote