Write program which will allow person to play guessing game

Assignment Help JAVA Programming
Reference no: EM131945744

Assignment: Programming foundations in Java

Guessing Game

1608_Gue55ing-Game.jpg

Specification

For this assignment you will write a program which will allow a person to play a number guessing game against the computer. This section specifies the required functionality of the program. Only a text interface is required for this program; however, more marks will be gained for a game that is easy to follow with clear information/error messages to the player.

The aim of Gue55ing Game is for a person and the computer to compete against other to correctly guess a hidden number.

A game consists of four rounds. For each round a number between 1 and 100 (inclusive) is randomly generated and the players (person and computer) take turns to guess the number. The round ends when the correct guess is given or each player has had three guesses.

If a player guesses the number correctly then they are awarded points according to how many attempts were taken to guess the number. If the round ends without either player guessing correctly then the points are awarded to each player according to how close they were to the hidden number.

At the end of the four rounds the player with the highest cumulative score wins the game.

Game play

The Gue55ing Game game begins with a message inviting the human player to enter their name. The name can only contain characters (except all spaces, including leading and trailing spaces) and must be between 1 and 8 characters in length (inclusive). The other player will be the computer. A number with a value from 1 to 100 (inclusive) is randomly generated but hidden from the players. The player who will have the first turn at guessing the number is then randomly chosen by the computer. The round then progresses with the players taking turns until the correct number is guessed. Note that your program will generate a number guess for the computer player.

The following are the game rules:

• If the number is not guessed correctly then a message is displayed indicating whether the entered number was higher or lower than the hidden number and the other player takes a turn. Note this means that after each turn the range of possible numbers is reduced. For example:

o When the game starts the original range is 1 - 100. The hidden number generated is 75

o First turn, the player guesses 50, this is lower. So now the new range for the computer to guess is between 51 and 100.

o Second turn, the other player guesses 90, this is higher. So now the new range for the player to guess is between 51 and 89.

o This goes on for each guess.

• If the player enters a number between 1 and 100 but not within the range of possible numbers (as explained above), then the player is given a warning message but is not given a chance to renter the number.

• If the player enters a number less than 1 or greater than 100, then a warning message is displayed and the player is invited to enter another number (with no penalty).

• If the player enters non-numeric characters, then a warning message is displayed and the player is invited to enter another number (with no penalty).

• If the human player enters 999 this indicates that they have decided to abandon the round. To simulate this for the computer player, at the start of each round, generate a random number between 1 and 20. This number will be known as the ‘abandon round indicator'. Then before each guess the computer player makes, generate a random number between 1 and 20. If this number is the same as the ‘abandon round indicator' then the round is abandoned. If these numbers are not the same, the computer continues with its guess of the hidden number.

o Abandoning a round means no scores are assigned to either player for that round.

• If a player correctly guesses the number then the round ends, points are awarded to this player according to how many attempts have been made. Note the total number of attempts includes attempts by both players. The other player scores zero for the game.

Number of attempts

Score

1

20

2

15

3

11

4

8

5

6

6

5

• If the round ends and no player has guessed the number then each player is awarded a score according to the proximity of their last guess to the hidden number, as follows:

score = 10 - proximity-of-last-guess
(Note if proximity-of-last-guess is 10 or more then the score is 0 (zero))

For example, if the hidden number was 63 and the last guess for player1 was 53 and the last guess for player2 was 68, then player1 would score 0 (zero) and player2 would score 5.

Note: the ‘last guess' here is referring to the third guess of each player in that particular round.

Program design

Your program should consist of at least three classes: Player, Game and RandomNumber. The following two sections give details of these classes. Students are advised to follow good programming practices and to use loops and appropriate field where required to ensure good program design.

Player class

The Player class will specify the attributes and behaviours of a player. An object of the Player class will have the following fields (at least):

Name - the name of the player.

Score - the cumulative game score

Guesses - the last number guessed for the current round

The data type of each field must be chosen carefully and you must be able to justify the choice of the data type of the fields. You may want to include comments in the class to state the assumption made. The class must also have a default constructor and a non-default constructor that accepts a value for the name of the player.

The Player class should also have appropriate accessor and mutator methods for its fields. You should not allow an object of class Player to be set to an invalid state. There should be no input from the terminal or output to the screen. A Player object should also be able to return its state in the form of a String.

Game class

The Game class will be in the same BlueJ project that contains your Player class. The Game class will manage the playing of a game. It will have the following fields (at least):

Player1 (an object of type Player) Player2 (an object of type Player)

Note that one of these players will be the computer.

The Game class will have methods to manage the playing of the game. These should include (at least) the following behaviours:

• Display a welcome message on the screen.
• Request the player to enter their name.
• Request the player to enter a number.
• Compare the number entered by a player with the hidden number.
• Display the result of the attempt at guessing the number.
• Display the result for the end of a round (including the value of the hidden number).
• Display the game result.

RandomNumber class

An object of the RandomNumber class will generate a random number from 1 to a maximum value specified.

Reference no: EM131945744

Questions Cloud

If you were the judge in this case what would you decide : Sam began his academic career majoring in Biology, but then shifted his major to history, then to Creative Writing, and then to Mathematics.
What is the age of the rock : Assuming that the only chemical process is radioactive decay of potassium to argon, what is the age of the rock?
What are possible reforms to increase the accountability : What appear to be the most pressing problems in corporate governance? What are possible reforms to increase the accountability of corporate managers
What will be yearly annuity for the next given years : Betty Bronson has just retired after 25 years with the electric company. Her total pension funds have an accumulated value of $350,000.
Write program which will allow person to play guessing game : For this assignment you will write a program which will allow a person to play a number guessing game against the computer.
Complete a profit and loss report for year ending : Complete a Profit and Loss report for year ending 30 June 20XX as well as a debt-to-equity ratio for the 2008 financial year
Create an argument supporting whether sox achieved the goals : Create an argument supporting whether SOX achieved these goals, and whether financial data reported today is more accurate and reliable than prior to the Act.
Find the cost and schedule variances and the cpi and spi : A sales project at month 5 had an actual cost of exist34,000, a planned cost of exist42,000, and a value completed of exist39,000.
Computing the monthly savings : Bilbo Baggins wants to save money to meet three objectives. First, he would like to be able to retire 30 years from now with a retirement income of $31,500.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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