Question: Write a Java program that simulates a matching game with the instructions below. A UML diagram, skeleton program, and sample runs are provided below. ----------

Write a Java program that simulates a matching game with the instructions below. A UML diagram, skeleton program, and sample runs are provided below.

Write a Java program that simulates a matching game with the instructionsbelow. A UML diagram, skeleton program, and sample runs are provided below.

----------

UML DIAGRAM

---------- UML DIAGRAM ------- SKELETON PROGRAM: package Lab09; import java.util.*; /** *

-------

SKELETON PROGRAM:

package Lab09; import java.util.*; /**  *  * @author atb  * @version 10/23/2018  */ public class MatchingGame { private ArrayList theNumbers; private final int MAX_NUMBER_OF_SHUFFLES = 5; private final int MIN_NUMBER = 10; private final int MAX_NUMBER = 99; private Random generator; public MatchingGame(int numberAmount) { this.theNumbers = new ArrayList(); initializeList(numberAmount); } /**  * Initialize the list with the count of random 2 digit numbers.  *  */  private void initializeList(int numberAmount) { // TODO Project 6a  this.generator = new Random(11); ListIterator iter = this.theNumbers.listIterator(); // generate the numbers and add them to theNumbers using iterator } /**  * See whether two numbers are removable.  * @param first the first 2 digit integer value  * @param second the second 2 digit integer value  * @return true if the first and second match  */  private boolean removablePair(Integer first, Integer second) { // TODO Project 6c   // implement this method return false; } /**  * Implements one pass when called by play method  * Scans over the list and removes any pairs of values that are removable.  * @return true if any pair of integers was removed  */  private boolean scanAndRemovePairs() { // TODO Project 6d  boolean removedAPair = false; ListIterator scan = this.theNumbers.listIterator(); Integer first = null; Integer second = null; // implement the method // this method calls helper method removablePair to see if there is a match return removedAPair; } private void displayTheNumbers() { // TODO Project 6b   // using an instance of Iterator display the content of theNumbers // notify the user if the list is empty } public void play() { int pass = 0; int numberOfShuffles = 0; boolean repeat; System.out.println("Starting with: "); displayTheNumbers(); do { repeat = false; while (scanAndRemovePairs()) { pass++; System.out.println("The list after pass #" + pass); displayTheNumbers(); } System.out.println("No more pairs to remove."); // do we have at least 3 numbers in the list? if (this.theNumbers.size() > 2) { if (numberOfShuffles out.println("Shuffling the numbers."); Collections.shuffle(this.theNumbers, this.generator); System.out.println("The list after shuffling #" + numberOfShuffles); displayTheNumbers(); repeat = true; } } }while(repeat); if (this.theNumbers.isEmpty()) { System.out.println(" *** Winner!!! ***"); } else { System.out.println(" *** Better luck next time! ***"); } } public static void main(String[] args) { final int MIN_NUMBER_OF_ELEMENTS = 10; Scanner scan = new Scanner(System.in); int numberAmount; do { System.out.println("How many numbers (no less than " + MIN_NUMBER_OF_ELEMENTS + ")?"); numberAmount = scan.nextInt(); }while(numberAmount  

-----

SAMPLE RUNS:

* @author atb * @version 10/23/2018 */ public class MatchingGame { private

ArrayList theNumbers; private final int MAX_NUMBER_OF_SHUFFLES = 5; private final int MIN_NUMBER

= 10; private final int MAX_NUMBER = 99; private Random generator; public

MatchingGame(int numberAmount) { this.theNumbers = new ArrayList(); initializeList(numberAmount); } /** * Initialize

the list with the count of random 2 digit numbers. * */

private void initializeList(int numberAmount) { // TODO Project 6a this.generator = new

Random(11); ListIterator iter = this.theNumbers.listIterator(); // generate the numbers and add them

VI Matching Game Consider a matching game in which you have a list of random integer values between 10 and 99. You remove from the list any pair of consecutive integers that match If first integer has digits xlyl and the second integer has digits x2y2 the match is found if any of the following is true: *xl is the same as x2 *xl is the same as y2 *yl is the same as x2 *yl is the same as y2 If all integer values are removed, you win. You are allowed to shuffle the integer values up to 5 times to increase the probability of finding more matches For example consider the following sequence of integers: 70 8243 23 89 12 43 84 93 17 The pair 70 and 82 does not match in either digit and so cannot be removed, next check 82 and 43, no match either. Next check 43 and 23, there is a match, so both values are removed. Continue checking for pairs from 89, which is the value after the removed pair. Once you finish the first pass the following sequence remains 70 8289 12 93 17 Now return to the beginning of the list and check the pairs again. After the second pass the following sequence remains 70 1293 17 Now return to the beginning of the list and check for the pairs again. This time no matches were found, so shuffle the list and try again. You are allowed to shuffle maximum 5 times VI Matching Game Consider a matching game in which you have a list of random integer values between 10 and 99. You remove from the list any pair of consecutive integers that match If first integer has digits xlyl and the second integer has digits x2y2 the match is found if any of the following is true: *xl is the same as x2 *xl is the same as y2 *yl is the same as x2 *yl is the same as y2 If all integer values are removed, you win. You are allowed to shuffle the integer values up to 5 times to increase the probability of finding more matches For example consider the following sequence of integers: 70 8243 23 89 12 43 84 93 17 The pair 70 and 82 does not match in either digit and so cannot be removed, next check 82 and 43, no match either. Next check 43 and 23, there is a match, so both values are removed. Continue checking for pairs from 89, which is the value after the removed pair. Once you finish the first pass the following sequence remains 70 8289 12 93 17 Now return to the beginning of the list and check the pairs again. After the second pass the following sequence remains 70 1293 17 Now return to the beginning of the list and check for the pairs again. This time no matches were found, so shuffle the list and try again. You are allowed to shuffle maximum 5 times

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!