Answered step by step
Verified Expert Solution
Link Copied!

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 game-variables and match-variables, 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 game/match 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 Tile-Input: 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 single-digit numbers (separated by a space). Several techniques exist to parse the tile-input.
Technique #1: Understanding that only single-digit 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 digit-characters to obtain a numerical representation of the data which can then be used to index the 9-element boolean array to "close" the appropriate tile. Refer to section 3 of chapter 4 in the textbook, the RandomChars program, and the SaltPassword project.
Technique #2: Process the user-defined tile-input (such as "234" or "54" or "9" for a dice roll summing to 9) as a String object. Then, the data (tiles) can be extracted using a loop and an Integer static-method; refer to the "Error-Checking" section for more information on the Integer static-method.
Technique #3: 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 tile-input (that is read into the program as a String).
Example #1: 1 run with 1 winner:
Welcome to the 'Shut the Box' Game.
Begin playing game #1.
Enter a seed:
-44
The available number(s) are: 123456789
The dice roll is 6 and 5 for a sum of 11.
Which tile(s) should be "closed"? Separate multiple tiles with a space.
38
The available number(s) are: 1245679
The dice roll is 6 and 3 for a sum of 9.
Which tile(s) should be "closed"? Separate multiple tiles with a space.
9
The available number(s) are: 124567
The dice roll is 3 and 5 for a sum of 8.
Which tile(s) should be "closed"? Separate multiple tiles with a space.
17
The available number(s) are: 2456
The player may opt to roll 1 die or 2 dice because tiles 7,8, and 9 are "closed".
Enter "1" to roll 1 only die or "2"(or any other key) to roll 2 dice.
2
The dice roll is 1 and 3 for a sum of 4.
Which tile(s) should be "closed"? Separate multiple tiles with a space.
4
The available number(s) are: 256
The player may opt to roll 1 die or 2 dice because tiles 7,8, and 9 are "closed".
Enter "1" to roll 1 only die or "2"(or any other key) to roll 2 dice.
1
The die roll is 2.
Which tile(s) should be "closed"? Separate multiple tiles with a space.
2
The available number(s) are: 56
The player may opt to roll 1 die or 2 dice because tiles 7,8, and 9 are "closed".
Enter "1" to roll 1 only die or "2"(or any other key) to roll 2 dice.
2
The dice roll is 4 and 2 for a sum of 6.
Which tile(s) should be "closed"? Separate multiple tiles with a space.
6
The available number(s) are: 5
The player may opt to roll 1 die or 2 dice because tiles 7,8, and 9 are "closed".
Enter "1" to roll 1 only die or "2"(or any other key) to roll 2 dice.
1
The die roll is 5.
Which tile(s) should be "closed"? Separate multiple tiles with a space.
5
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 0 with 1 win(s) after 1 round(s).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

Understand the different approaches to job design. page 167

Answered: 1 week ago