Write program that allow user to play a simple guessing game

Assignment Help Programming Languages
Reference no: EM131270723

Programming Assignment

This assignment will give you practice with while loops and pseudorandom numbers. You are going to write a program that allows the user to play a simple guessing game in which your program thinks up an integer and allows the user to make guesses until the user gets it right. For each incorrect guess you will tell the user whether the right answer is higher or lower. Your program is required to exactly reproduce the format and behavior of the log of execution at the end of this write-up, so you may want to look that over first.

At a minimum, your program should have the following static methods in addition to method main:

- a method to give instructions to the user
- a method to play one game with the user (just one game, not multiple games)
- a method to report overall results to the user

You may define more methods than this if you find it helpful, although you will find that the limitation that methods can return only one value will tend to limit how much you can decompose this problem.

You are to define a class constant for the maximum number used in the guessing game. The sample log shows the user making guesses from 1 to 100, but the choice of 100 is arbitrary. By introducing a constant for 100, you should be able to change just the value of the constant to make the program play the game with a range of 1 to 50 or a range of 1 to 250 or some other range starting with 1.

When you ask the user whether or not to play again, you should use the "next()" method of the Scanner class to read a one-word answer from the user. You should continue playing if this answer begins with the letter "y" or the letter "Y". Notice that the user is allowed to type words like "yes".

You are to look just at the first letter of the user's response and see whether it begins with a "y" or "n" (either capitalized or not) to determine whether to play again.

Assume that the user always types an integer when guessing, that the integer is always in an appropriate range and that the user gives you a one-word answer beginning with "y", "Y", "n" or "N" when asked whether to play again.

You will notice at the end of the log that you are to report various statistics about the series of games played by the user. You are to report the total number of games played, the total number of guesses made (all games included), the average number of guesses per game and the maximum number of guesses used in any single game.

Here are a few helpful hints to keep in mind.

- This program needs to generate pseudorandom numbers. This is described in section 5.2.3 of the book.

- To deal with the yes/no response from the user, you might want to use some of the String class methods described in section 3.5.1 and 4.5 of the book. You will want to use the next() method of the Scanner class to read a word from the console.

- Because this program uses pseudorandom numbers, you won't be able to recreate this exact log. The key requirement is that you reproduce the format of this log and that your calculations for overall statistics are correct for your log.

- It's a good idea to change the value of your class constant and run the program to make sure that everything works right with the new value of the constant. For example, turn it into a guessing game for numbers between 1 and 5.

This program is more difficult than most to decompose into methods, so you may end up having methods that are longer than 15 lines. You can also include more code in your main method than I allowed in the last program. In particular, you are required to have a while loop in main that plays multiple games and prompts the user for whether or not to play another game. You shouldn't have all of the code in main because you are required to have the methods described at the beginning of this write-up.

Reference no: EM131270723

Questions Cloud

Relationship between human resource planning activities : Discuss the relationship between human resource planning activities and the organization's strategic development and implementation. Describe the eight elements of the staffing process. Examine the relationship between the eight elements of the st..
Recently proposed required bystander rule : Some Washington State legislators have recently proposed a required "bystander" rule so that people who come upon a person in distress would be required to assist that person, or have a criminal charge imposed. Do you think the State of Washington sh..
What are the main points and arguments of the author : In your critique, address the following questions: What are the main points and arguments of the author(s)? What is your opinion of the article
What is the difference between inside vs. outside director : There are three internal governance mechanisms: ownership concentration, board of directors, and executive compensation. Regarding the board of directors: What is the difference between an inside vs. an outside director? In your opinion, should a cor..
Write program that allow user to play a simple guessing game : This assignment will give you practice with while loops and pseudorandom numbers. You are going to write a program that allows the user to play a simple guessing game in which your program thinks up.
Please just turn this thing off : A nursing assistant wheels Margie Whitson back to her room at Golden Oaks Rehabilitation Center and helps her back into bed. Golden Oaks is located on the grounds of Marion General Hospital, owned and operated by the hospital board of directors.
What percentage of parts will not meet the weight specs : Specifications for a part for a DVD player state that the part should weigh between 24.9 and 25.9 ounces. The process that produces the parts has a mean of 25.4 ounces and a standard deviation of .22 ounce. The distribution of output is normal. Use T..
Moon shoots of managments : 1. Explain the 10 moon shoots of managments and write in paragraphs.
Service capacity to in order to stay out of critical zone : Owners of a local restaurant are concerned about their ability to provide quality service as they continue to grow and attract more customers. They have collected data from Friday and Satuday nights, their busiest times of the week. How much will the..

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a checkbook application

I have attached a zip file of what I have completed so far in this checkbook organizer program. I need to edit this program so that the transactions entered into the checkbook application are able to be double clicked and view the details from a s..

  Create a very abstract programming environment

Find these header files in the Visual Studio system and determine the smallest (i.e., most negative) and largest (i.e., most positive) values that can be represented as int, unsigned int, long, unsigned long, float and double.

  Creating application to test class rectangle

Write down application to test class Rectangle.

  Client program that returns the number of items in a queue.

Implement the following specification for an integer function in the client program that returns the number of items in a queue.

  Which protocol is using by video game programmers udp or tcp

What protocol do you think video game programmers would use UDP or TCP. Why do you think the game uses one or the other protocols

  Analysis the advantages and disadvantages of social network

Analyze how the university might integrate at least two social media and networking technologies to accomplish their goals. Your analysis must cover the advantages and disadvantages of social networking.

  Aggregate planning for a bottling companya bottling company

aggregate planning for a bottling companya bottling company has decided to introduce a new line of premium bottled

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Project code in visual studio console application

Project code in visual Studio Console application and class library and the PADI project aims at implementing a simpli ed distributed software transactional system.

  Write program to read two-digit hexadecimal sequences

Write down the program which reads 2-digit hexadecimal sequences from the text file and shows their decimal equivalents.

  Describe create table command

Find the patients who have made an appointment with a doctor who does not treat them.

  What is the difference between an interpreter and a compiler

What are the general stages in the development of an expert system? What occurs in each stage?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd