Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: Homework 2: Guessing Your Number Summary: We will create a program that will guess a number between 1 and 100 chosen by the user.

JAVA: Homework 2: Guessing Your Number

Summary: We will create a program that will guess a number between 1 and 100 chosen by the user. This will be your first exercise in algorithm design, and the best way to go about this is to read through the entire problem document at least once before you start actually doing any coding.

Objectives: We will build a simple game application that uses all the fundamental concepts that we have covered from Chapters 1-3. Since this isnt just a programming class (its also a software design course) its important that you learn to code using software engineering practices used by industry. We use a topdown stepwise refinement approach (p.88) to develop our algorithm. Your program will be iteratively built in several stages, where each stage focuses on implementing just one type of operation. Each stage will build upon the work from the previous stage. This is known as iterative design, a process that allows us to focus on working on a single, simple task at a time, but the resulting software slowly evolves into something much more complex. Required Concepts: The final homework requires that you implement the following concepts: 1. Storage operations (store data in program) 2. Output operations (print data to screen) 3. Input operations (get data from user) 4. Selection operations (multiple selection based on player input) 5. Mathematical operations (arithmetic, equality, relational) 6. Repetition operations (loop game logic to model multiple turns) 7. Nested selection operations (validate that users selection meets rules requirements)

Initialize a variable that represents the lowest possible number to 0 (what type should this be?)

Initialize a variable that represent the highest possible number to 100 (what type should this be?)

Initialize a Boolean variable that represents if weve achieved the correct guess to false

Initialize a variable in which to store the number of guesses weve made to 0

Declare a variable in which to store an initial guess

Declare a variable to store user input (make this an int)

Initialize a Scanner object (call the variable you assign it to input for consistency with class examples)

Prompt the user to choose a number (this is simply output the program shouldnt know the number)

Make an initial guess and store it.

Increment the value in the variable storing number of guesses.

Present guess to the user

Present prompt to user (Enter 1 if this was a correct guess, 2 if your number is higher, and 3 if your number is lower:)

Use Scanner to grab the nextInt() the user types in, and store it. If the user has typed in a 1

Change the value of the Boolean variable (correctGuess) to true. While we havent guessed the correct number (correctGuess == false)

Modify range for next guess

Generate a next guess

Present guess to the user

Present prompt to user (Enter 1 if this was a correct guess, 2 if your number is higher, and 3 if your number is lower:)

Use Scanner to grab the nextInt() the user types in, and store it. If the user has typed in a 1

Change the value of the Boolean variable (correctGuess) to true.

Print out how many steps it took to guess the number

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane X z 2/3 90% a/3

Answered: 1 week ago