Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#Java My code is at the end of the post. And I am tracked into several problems. My original thinking is to create a 4x4

#Java

My code is at the end of the post. And I am tracked into several problems.

My original thinking is to create a 4x4 array first, in this order: (A,A, Q,Q K,K J,J,2, 2,5, 5, 6,6,9, 9), and then shuffled the card.

1. However, when I shuffled the card, some cards were missing, and it will turn out like A,A,A,Q,Q,2,2,2.... (Which means the card is no longer a pair anymore)

2. I found I only can type the row and column of the array I want to guess in 0-3, rather than 1-4

3. When I guess wrong(which means the cards I choose are two different numbers), the card won't face down into $ sign.

4. When I guess the second times, I found the position of the card change again... it's position is from the first time I play.

5. I need to complete the game in OOP...

The question is:

image text in transcribed

__________________________________________________

package Question1; import java.util.Scanner; public class Shuffle { public static String[][] array = {{" A", " A", "10", "10"}, {" K", " K", " J", " J"}, {" 2", " 2", " 5", " 5"}, {" 6", " 6", " 9", " 9"}}; public static void main(String[] args) { originalCardOrder(); shuffle(); coverCard(); finalTable(); } public static void originalCardOrder(){ for(int i=0; iout.print(" " +array[i][j]+ " "); } System.out.println(); } } // Shuffle the cards randomly public static void shuffle() { System.out.println(); for (int i = 0; i random() * 4); int j1 = (int) (Math.random() * 4); String temp = array[i][j]; array[i][j] = array[i1][j1]; array[i1][j1] = temp; System.out.print(" " + "" + array[i][j] + "" + " "); } System.out.println(); } } // Make a table that makes the cards face down public static void coverCard() { for (int i = 0; i out.print(" " + " $ " + " "); } System.out.println(); } } public static void finalTable() { String[][] finalTable = new String[4][4]; for (int i = 0; i in); System.out.println("Type the row between 1-4 you want: "); int rowTest1 = scan.nextInt(); System.out.println("Type the column between 1-4 you want: "); int colTest1 = scan.nextInt(); finalTable[rowTest1][colTest1] = String.valueOf(array[rowTest1][colTest1]); System.out.println("Type the row between 1-4 you want: "); int rowTest2 = scan.nextInt(); System.out.println("Type the column between 1-4 you want: "); int colTest2 = scan.nextInt(); finalTable[rowTest2][colTest2] = String.valueOf(array[rowTest2][colTest2]); for (int i = 0; i out.print(finalTable[i][j]); } System.out.println(); } if (finalTable[rowTest1][colTest1].equals(finalTable[rowTest2][colTest2])) { count++; }else{ System.out.println(); System.out.println(); System.out.println(); finalTable[rowTest1][colTest1] = " $ "; finalTable[rowTest2][colTest2] = " $ "; continue; } } } } 
Write a program that plays this game of concentration. Use 16 cards that are shuffled and laid out ina 4 by 4 square. These cards should be labeled with pairs of card numbers (A, Q, K, J, 2, 5, 6, 9) Your program should allow the player to specify the cards that she would like to select through a coordinate system For example, in the following layout: 1 2 3 4 1 A S $$ All of the cards are face down indicated by $. The pairs of A which are face up and at coordinates (1,1) and (2,3) . To hide the cards that have been temporarily placed face up, output a large number of newlines to force the old board off the screen (or find something better in the JAVA API)

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

Students also viewed these Databases questions