QuestionQuestion

Create an application based on the specifications given that lets a user play a game.
Example Console Display Test
Specifications
1. There are many ways to design a solution to this problem but you are evaluated on meeting the specific specifications as given in this quiz.
2. Use proper statement indentation and meaningful variable names in the code. (3 points)
3. Place a multi-line comment (not multiple single line comments) giving a description of what this application does before the class header. Include your name and the date with the description. (2 points)
4. Output spacing, formatting, and spelling are to match the example console output illustrated above, but of course the user input will be different. (5 points)
5. Add a meaningful comment for every statement explaining why the statement is in the code. (5 points)
6. Prompt the user for data.
7. Validate the data so only acceptable values will be processed. If the user enters invalid data, the application should display the appropriate error message and prompt the user again until the user enters valid data. See example console display above. (5 points)
8. The user will have the option of running the application again with all new input values. When the user responds to the “Play Again?” prompt, the application should only accept a value of “yes” or “no”. (5 points)
9. If the user enters invalid data at any time in the application, the application should display an appropriate error message and prompt the user again until the user enters valid data. See example console display test above.
10. Create and use an interface with an abstract method called printPlayers that does not return any values. This interface will be implemented in the class with the main method and the other methods listed below. (4 points)
11. Create a class named Player with four instance variables. One is for the player’s name, the second is for the amount of money the player has, the third is an array of guesses, and the fourth is for the wager amount. (4 points)
12. Create getter and setter methods for the instance variables. (4 points)
13. Create two Player constructors. One will have no parameters and one will have the name and the amount of money parameters. (4 points)
14. You will use this class in the application to create Player objects. (5 points)
15. Use the Console class from chapter 7 in the textbook to validate user entered data. (4 points)
16. Use an ArrayList to store Player objects in the main method. (5 points)
17. Use a LinkedList to store the three winning numbers. (5 points)
18. The application must contain and implement these nine methods. Name them whatever you like. The functionality they will perform in the application is summarized below:
o main method- This method will declare and initialize necessary entities and control execution of the code. Anything not handled is the other methods will be accomplished by the main method. (5 points)
o random number generator method- This method will generate a value between 0 and 20 inclusive. (3 points)
o Initial welcome display and initial user input method - This method will display the welcome information and will prompt, accept, and validate the user's response to the first prompt . (2 points)
o winner method - This method determines if the player wins or loses, and displays the appropriate information to the user. (5 points)
o User wage validation and input method- This method will display the wagering information and will prompt, accept, and validate the user’s wager. (5 points)
o User guess validation and input method- This method will display the guessing prompt and will prompt, accept, and validate the user’s three guess. (5 points)
o Create player method – This method will prompt, accept, and validate the data needed to create a player object. (5 points)
o Play again method– This method will prompt, accept, and validate the data needed to continue playing with brand new players from the beginning and print appropriate information in response. A call to the printPlayer method will print the players and their ending balances. (5 points)
o printPlayer method – This method will print the players' names and their ending balances. (5 points)

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Random;
import java.util.Scanner;

/**
* This the main entry point class of the project.
* It has 9 methods each having a specific responsibility.
* It allows players to play Casino Royal game, where
* it randomly generates three wining number,
* then it asks each player to guess three number,
* if a player successfully guessed any of the winning number,
* he/she wins the bet amount, otherwise, losses
* accordingly.
*/
public class Application implements PrintHandler{

    // List will hold the player objects.
    private ArrayList<Player> players;

    // Linked list to store the winning numbers.
    private LinkedList<Integer> winningNumbers;

    /**
    * Default constructor of Application
    * class, it initialises the member
    * variables.
    */
    public Application() {
       // Initialising player list
       players = new ArrayList<>();

       // Initialising winning numbers list
       winningNumbers = new LinkedList<>();
    }

    /**
    * Entry point of the program.
    * This method declares and initialize necessary entities
    * and control execution of the code.
    * @param args
    */
    public static void main(String[] args) {

       // Scanner to take input values
       Scanner scanner = new Scanner(System.in);

       Application application = new Application();

       // Looping unless user quits the game
       do {
            // Prompting welcome screen, asking for number of players
            // and their information.
            application.welcome(scanner);
            for(Player player: application.players) {
                application.guessValidationInputData(scanner, player);
            }
            // Seeking information about wager of each player
            for(Player player: application.players) {
                application.wagerInfo(scanner, player);
            }
            // Checking the results or winners.
            System.out.println("Very good. Spinning the wheel.....");
            for(Player player: application.players) {
                application.checkWinner(player);
            }
       } while (application.playAgain(scanner)); // Asking user information, if they want to play again.
    }

    /**
    * This method will display the welcome information and will prompt,
    * accept, and validate the user's response to the first prompt
    * @param scanner
    */
    public void welcome(Scanner scanner) {

       // Clearing previously created list of players if any.
       players.clear();

       // Clearing previously created list of winning numbers if any.
       winningNumbers.clear();

       // Adding 3 random numbers to winning number list.
       winningNumbers.add(generateRandom());
       winningNumbers.add(generateRandom());
       winningNumbers.add...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$30.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats