Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M92784400

Have any Question?


Related Questions in Java

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As