Question: IN JAVA You are to write a program called NGuesses. This program will ask you to guess a number and it gives you only N

IN JAVA

You are to write a program called NGuesses. This program will ask you to guess a number and it gives you only N number of guesses (meaning that the number of guesses can vary but is set at the beginning of the program). You will will have a text-based interface that controls the flow of the game (see below for the required output)

Requirements

Your program will read in three command line arguments. No error checking is required, you can assume you will always have valid command line input

The first is the number of guesses (type: int you can assume 1 or greater)

The second is the "picked" number to guess. We are assuming you are setting up the game for someone else to actually have to try and guess the number (type:int any valid Java int )

The third is the prize a person wins if they guess the correct number before running out of guesses (type: String)

You may assume that the player always guesses a valid int. You will provide an appropriate message (see example below for actual text) depending on whether the number guessed is lower, higher or equal than the actual number.

If the player guesses correctly within the allowed number of guesses, print the message (substitute PRIZE for the String that was the third command line argument)

Congratulations, you won a PRIZE!

If the player exceeds the number of allowed guesses, print the message (substitute N for the correct number)

Sorry you didn't win, the number was N

Example: java NGuesses 4 7 Duck

Input shown in blue

Enter a guess:

5

Too low

Enter a guess:

8

Too high

Enter a guess:

7

That's the right number

Congratulations, you won a Duck!

Example: java NGuesses 2 -3 '$1,000,000'

Input shown in blue

Enter a guess:

5

Too high

Enter a guess:

0

Too high

Sorry you didn't win, the number was -3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!