Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:28:01+00:00 2026-06-14T22:28:01+00:00

I am trying to do a matching game here and I am almost done.

  • 0

I am trying to do a matching game here and I am almost done. After the userInput is given, I am trying to replace the gameboard with the hidden value. I have writen the code to see if “A1” will work but it won’t. Does anyone have any ideas on how to replace an element of an array with another element? Or am I doing it wrong?

import java.util.*;
public class breitje_MatchUp{
   static Scanner input = new Scanner(System.in);
   static int i=0, count=0;
   static char[][] clearBoard = new char[4][4];
   static char[][] board = new char[4][4];
   public static void main(String[] args){
      gamePlay();

   }

   public static void drawMenu(){
      System.out.println("Welcome to the Match Up game! \n");  
      System.out.println("Please select from the following: ");  
      System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");  
      System.out.println("1. New Game");  
      System.out.println("2. Quit");  
      System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");  
      int optionSelect = input.nextInt();
      System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");  
      while(optionSelect!=1 && optionSelect !=2){
         System.out.println("Please enter 1 (New Game) or 2(Quit)");
         optionSelect = input.nextInt();}
      if (optionSelect == 1)
         System.out.print("START GAME HERE********");
      else if (optionSelect == 2)
         System.out.println("Thanks for playing! Have a great day.");  
   }


   public static char[][] buildBoard(){
      char[][] board = new char[4][4];
      for(int i = 0; i <board.length; i ++){
         for(int j = 0; j<board[0].length;j++){
            board[i][j]=(char)(65+Math.random()*8);
         }
      }
      return board;
   } 

   public static void drawBoard(){
      for(int row1 = 0; row1 < 4; row1++) {
         // this will create a new line for each new row
         System.out.println("");
         for(int col1 = 0; col1 < 4; col1++) {
            // this will print out the 4 row variable values
            clearBoard[row1][col1]='.';
         }        
      }
      System.out.format("   %2s %2s %2s %2s \n",'A','B','C','D');
      System.out.format("   %2s %2s %2s %2s \n",'-','-','-','-');
      System.out.format("1 |%2s %2s %2s %2s \n",
          clearBoard[0][0],
          clearBoard[0][1],
          clearBoard[0][2],
          clearBoard[0][3]);
      System.out.format("2 |%2s %2s %2s %2s \n",
          clearBoard[1][0],
          clearBoard[1][1],
          clearBoard[1][2],
          clearBoard[1][3]);
      System.out.format("3 |%2s %2s %2s %2s \n",
          clearBoard[2][0],
          clearBoard[2][1],
          clearBoard[2][2],
          clearBoard[2][3]);
      System.out.format("4 |%2s %2s %2s %2s \n",
          clearBoard[3][0],
          clearBoard[3][1],
          clearBoard[3][2],
          clearBoard[3][3]);  
   } 


   public static void gamePlay(){
      while(!checkForWin(count)){
         drawBoard();
         System.out.print("Card 1: Column/Row (Ex: A3) : "); //input 1
         String userInput = input.nextLine(); System.out.println();
         userInput = userInput.toUpperCase().trim();

         convertInput(userInput);

         drawBoard();

         System.out.print("Card 2: Column/Row (Ex: A3) : "); //input 2
         String userInput1 = input.nextLine(); System.out.println();
         userInput1 = userInput.toUpperCase().trim();
      }
      drawMenu();
   }
   public static void convertInput(String input){
      if(input.equals("A1"))
         clearBoard[0][0]=board[0][1];

   }

   public static boolean checkForWin(int count){
      if (count == 8)
         return true;
      else
         return false;
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:28:02+00:00Added an answer on June 14, 2026 at 10:28 pm

    The change you make is being overwritten by the draw method.

            clearBoard[row1][col1]='.'; // this will print out the 4 row variable values            
    

    It’s not clear to me what you’re trying to accomplish in this method, since the comment completely disagrees with the code – you’re setting the values to a period, not printing anything out at that line.

    There’s a lot of style things to improve here as well – a method named draw should not have the side effect of resetting the board.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a matching game for learning arabic. I have populated
I'm trying to implement java like url pattern matching in php. Suppose i have
I am trying to return a value (ID), matching another field (Type) in the
I am trying to get a product matching some custom parameters. So I have
After hours of trying to wrap my head around pattern matching, I'm throwing the
I'm trying to get a next field after matching field using awk. Is there
I'm making a turn based game, and trying to construct the matching function, when
Trying to get a handle on pattern matching here-- coming from a C++/Java background
I am trying to do Regular Expression matching. I have all the functions written
I am trying to make a simple card matching game via flash + actionscript,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.