Question: Write a program for a person to play a Prime Number Challenge. This section specifies the required functionality of the program. Only a text



Write a program for a person to play a Prime Number Challenge. This section specifies the required functionality of the program. Only a text interface is required for this program; The aim of the program is for a (player) see how many times they can correctly guess whether or not a number presented to them is a prime number. Each challenge consists of three rounds. For each round the player will be presented with a sequence of up to 10 randomly generated numbers within a specified range. The round ends when an incorrect guess is given, 10 numbers have been presented to the player or the player decides to quit the round. The challenge can be taken at one of two levels, which are defined by the range of numbers that the random number is generated from (1-100 or 1-400). Each level is played in easy or hard mode. The first round of the challenge will be played in easy mode. If the player achieves the maximum score on the first or second rounds they will be promoted to hard mode for the subsequent round(s). The hard mode will not use any numbers that are obviously not primes, so this makes it harder to correctly classify each number. At the end of each round the player is awarded a score according to the number of correct guesses and the mode they have played in for that round. After three rounds the player is shown their average score for the challenge. Rules of the challenge The Prime Number Challenge begins with a message inviting the player to enter their name. The name can contain only alphabetic characters (upper and/or lower case) and must be no more than 10 characters in length. If the player enters an invalid name then a warning message is displayed and the player is invited to enter another name. The player is then invited to choose the level of challenge they wish to play: Level 1 - the player will guess from randomly generated numbers in the range 1 to 100 (inclusive). Level 2 - the player will guess from randomly generated numbers in the range 1 to 400 (inclusive). The first round is played in easy mode. In easy mode the player is shown randomly generated numbers from the chosen range. For the hard mode, the numbers shown will not include any numbers that are obviously not prime numbers. For our purposes, any even numbers (numbers ending in 0, 2, 4, 6, or 8) or numbers ending in 5 should not be shown in hard mode. Playing a round The player is shown a series of random numbers generated according to the level of the challenge and mode for the round. For each number shown, the player is invited to nominate whether the number is a prime number by responding with "Y" or "N". The following are the possible outcomes: the player classifies the number correctly and there have been less than 10 numbers shown. In this case the next number is shown. the player classifies the number correctly and 10 numbers in total have been shown. In this case the round ends. the player classifies the number incorrectly. In this case the round ends. the player decides to abandon the round by entering "Q". In this case the round ends. At the end of the round the score for the round is displayed to the player. The score is calculated as follows: score = (total numbers classified correctly + completion bonus) * mode weighting where the completion bonus is 2 if 10 numbers are correctly classified and 0 otherwise) and the mode weighting is 1 for easy and 2 for hard mode If the player has classified 10 numbers correctly on rounds 1 or 2 then the subsequent rounds are played in hard mode as defined above The end of the challenge When three rounds have been played, the challenge finishes and the average score for the challenge is displayed. The player is then invited to play another challenge. Your program should consist of at least three classes: Player, PrimeChallenge, and Number Generator. The following two sections give details of these classes. Player class The Player class will specify the attributes and behaviours of a player. An object of the Player class will have at least the following fields: Name - the name of the player. TotalCorrect - the cumulative correct classifications for the current round Score - the cumulative game score 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 any assumptions 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. Validation of values for fields should also be implemented. 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. PrimeChallenge class The PrimeChallenge class will manage the playing of a Prime Number Challenge. It will have the following fields: Player - an object of type Player The Challenge class will have methods to manage the playing of the game. These should include the main() method to start the program and methods for the following behaviours: Display a welcome message on the screen. Request the player to enter their name. Request the player to enter the level of the challenge they wish to play. Check whether the player has classified the number correctly. Display the result of the attempt at classifying the number. . Display the result for the end of a round, including the score for the player. Display the challenge result.
Step by Step Solution
There are 3 Steps involved in it
Heres a simple implementation in Python for t... View full answer
Get step-by-step solutions from verified subject matter experts
