Write a program for a person to play a Prime Number Challenge. This section specifies the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image 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. 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.
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
What will be the value of x after executing the following java statement? Assume that value of x is 5 before the execution. x += x++ - 5;
-
GoodBuy sells gift cards redeemable for GoodBuy products either in store or online. During 2018, GoodBuy sold $1,000,000 of gift cards, and $840,000 of the gift cards were redeemed for products. As...
-
The data on the daily consumption of fuel by a delivery truck, in gallons, recorded during 25 randomly selected working days, are as follows: 9.7, 8.9, 9.7, 10.9, 10.3, 10.1, 10.7, 10.6, 10.4, 10.6,...
-
A woman stands in an elevator that is accelerating upward. Draw a free-body diagram for her.
-
Consider each case below independently. 1. Minden Companys required rate of return is 15%. The company can purchase a new machine at a cost of $40,350. The new machine would generate cash inflows of...
-
CWRU Biosciences has just completed their most recent year with the following results (in thousands): Sales 1,000 Net income 20 Dividends 0 Net assets 250 Equity 200 The company forecasts that it...
-
A division of your company purchased a large quantity of new desktop computers during the current fiscal year. An internal audit manager has asked you to audit the process used to acquire the...
-
Financial Analysis for Visa vs MasterCard what does Wall Street think? What is their position with regards to past performance and future performance? What are their expectations on each of the...
-
Jessica was provided with a motor vehicle which cost her employer $77,000 (inclusive of GST and luxury car tax) on 1 April 2021. Jessica travelled 22,000 kilo meters during the 2020-2021 FBT year, of...
-
Why is the Australian tax system more progressive than most OECD countries, for example, Denmark & Sweden?
-
How can winning a poker tournament at a casino be described as a business income vs it not be counted as any form of income?
-
A resident citizen reported the following for the year 2020: Net sales 8,000,000 Cost of sales 3,000,000 Salaries of employees, net of 100,000 withholding tax and 50,000 SSS, Medicare and Pag-ibig...
-
Smile Company is a domestic company engaged in manufacturing heavy machinery. Smile needs to order some specialty equipment from Churchill Company, a U.K. company which uses Libor as its functional...
-
Any example in which Good Laboratory Practices are not followed and it caused severe consequences (In medical research)?
-
How can NAFTA be beneficial to suppliers of Walmart?
-
A student is working part time as a hairdresser to pay college expenses. The student may work no more than 24 hours per week. Haircuts cost $25 and require an average of 20 minutes, and permanents...
-
Some Major League Baseball pitchers can throw a fastball at speeds of up to and over 100 miles per hour. Assume a Major League Baseball pitcher throws a baseball straight up into the air at 100 miles...
-
Evaluate the function at the given value of x. Round your result to three decimal places. Function ................................................................................. Value 1. f (x) =...
-
True or False: Engineers seldom have an opportunity to influence the recovery period for expenditures.
-
A lumber company purchases and installs a wood chipper for \(\$ 200,000\). The chipper is classified as MACRS 7-year property. Its useful life is 10 years. The estimated salvage value at the end of...
-
True or False: Straight-line depreciation is the most popular depreciation method used in financial reporting.
Study smarter with the SolutionInn App