Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java code all written in the main method Due to the various game - variables and match - variables, all the code should be contained
Java code all written in the main method
Due to the various gamevariables and matchvariables, all the code should be contained only within the main method. Other methods may be introduced to 'compartmentalize' code to facilitate readability and avoid repeating code unnecessarily; do not repeat code. However, since many gamematch variables need to change almost simulataneously and methods return only one variable, program development will be facilitated if all code is contained within the main method.
Processing TileInput: Use the Scanner method nextLine to input the selected tiles "close" into the program for processing as a String object due to the possibility that the input may contain multiple singledigit numbers separated by a space Several techniques exist to parse the tileinput.
Technique #: Understanding that only singledigit tiles exist and that the char data type are really int data just interpreted differently by Java loop through the String object and parse each character individually. A simple math operation can be performed on digitcharacters to obtain a numerical representation of the data which can then be used to index the element boolean array to "close" the appropriate tile. Refer to section of chapter in the textbook, the RandomChars program, and the SaltPassword project.
Technique #: Process the userdefined tileinput such as or or for a dice roll summing to as a String object. Then, the data tiles can be extracted using a loop and an Integer staticmethod; refer to the "ErrorChecking" section for more information on the Integer staticmethod.
Technique #: A Scanner object can be constructed using a String object as opposed to the "System.in input stream typically used in this course; refer to the "Constructor" section of the Scanner class in the Java API for more information. Then, the same powerful methods used to parse data from "the keyboard" on past programs such as next or nextInt can be used to parse the tileinput that is read into the program as a String
Example #: run with winner:
Welcome to the 'Shut the Box' Game.
Begin playing game #
Enter a seed:
The available numbers are:
The dice roll is and for a sum of
Which tiles should be "closed"? Separate multiple tiles with a space.
The available numbers are:
The dice roll is and for a sum of
Which tiles should be "closed"? Separate multiple tiles with a space.
The available numbers are:
The dice roll is and for a sum of
Which tiles should be "closed"? Separate multiple tiles with a space.
The available numbers are:
The player may opt to roll die or dice because tiles and are "closed".
Enter to roll only die or or any other key to roll dice.
The dice roll is and for a sum of
Which tiles should be "closed"? Separate multiple tiles with a space.
The available numbers are:
The player may opt to roll die or dice because tiles and are "closed".
Enter to roll only die or or any other key to roll dice.
The die roll is
Which tiles should be "closed"? Separate multiple tiles with a space.
The available numbers are:
The player may opt to roll die or dice because tiles and are "closed".
Enter to roll only die or or any other key to roll dice.
The dice roll is and for a sum of
Which tiles should be "closed"? Separate multiple tiles with a space.
The available numbers are:
The player may opt to roll die or dice because tiles and are "closed".
Enter to roll only die or or any other key to roll dice.
The die roll is
Which tiles should be "closed"? Separate multiple tiles with a space.
Congratulations, you won!
Do you wish to play again? Enter Yes to play again or anything else to quit.
No
Thank you for playing "Close the Box"! The total score is with wins after rounds
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started