Hello i have been having trouble trying to create a Matching game using classes and methods can you please help
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello i have been having trouble trying to create a Matching game using classes and methods can you please help
Do you have any specific questions about your assignment?
Please post your code and any questions about problems you are having.
What have you tried?
If you don't understand my answer, don't ignore it, ask a question.
Sorry, I forgot to ask you to use code tags.
Please edit your post and wrap your code with code tags:
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
What are your questions?
If you don't understand my answer, don't ignore it, ask a question.
Please edit your post and wrap your code with code tags:
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.
what do you mean to wrap the code with code tags
To wrap your code with code tags:
[code=java] <<<<<<<<<<<<< THIS goes before the code
<YOUR CODE HERE>
[/code] <<<<<<<<<<<< THIS goes after the code
--- Update ---
What is your problem with the code in post#9?
How can that code be compiled and executed for testing?
If you don't understand my answer, don't ignore it, ask a question.
To wrap your code with code tags:
<<<<<<<<<<<< THIS goes after the code<<<<<<<<<<<<< THIS goes before the code import java.util.*; public class Cards { private char label; private int cardNum; public Cards (int num) { cardNum = num; //making CardNum Equal to Intiger num1 reset(); } public void reset() { label = '*'; } public boolean flipCard() { if(label == '*') { label = convertToChar(); return true; } else return false; } public char convertToChar() { String temp = cardNum + ""; return temp.charAt(0); } public char getLabel() { return label; } public String toString() { return "" + label; } public boolean equals(Cards other) { return other.label == this.label; } public static void main(String[] args) { Cards p1 = new Cards(0); System.out.println("Card p1 = " + p1); System.out.println("We try and place a new card."); if(p1.flipCard()) System.out.println("Successful attempt! "); else { System.out.println("Failed attempt! "); } System.out.println("Card p1 = " + p1); System.out.println("We try to flip the card, but it's already flipped"); if(p1.flipCard()) System.out.println("Successful attempt! "); else System.out.println("Failed attempt! "); System.out.println("Card p1 = " + p1); System.out.println("We reset p1."); p1.reset(); System.out.println("Card p1 = " + p1); } }
--- Update ---
and i have 2 more
Sort of a waste of time if you delete all the posted code.
If you don't understand my answer, don't ignore it, ask a question.
<<<<<<<<<<<< THIS goes after the code<<<<<<<<<<<<< THIS goes before the code import java.util.*; public class Board { public static void Board(){ Cards [][] c = new Cards[4][4]; c[0][0]=new Cards(1); c[0][1]=new Cards(2); { } } }
import java.util.*;
public class Cards {
// Cards
//instance variables
private char label;
private int cardNum;
//constructor
public Card (int num);
{
cardNum = num; //making CardNum Equal to Intiger num1
reset();
}
//mutator methods
public void reset()
{
label = '*';
}
public boolean flipCard()
{
if(label == '*')
{
label = convertToChar();
return true;
}
else
return false;
}
public char convertToChar()
{
String temp = cardNum + "";
return temp.charAt(0);
}
//accessor methods
public char getLabel()
{
return label;
}
public String toString()
{
return "" + label;
}
public boolean equals(Card other)^
{
return other.label == this.label;
}
public static void main(String[] args)
{
Card p1 = new Card();
System.out.println("Card p1 = " + p1);
//Place a new card on the blank p1
System.out.println("We try and place a new card.");
if(p1.flipCard())
System.out.println("Successful attempt! ");
else
{
System.out.println("Failed attempt! ");
}
System.out.println("Card p1 = " + p1);
//Place a new card on the taken p1
System.out.println("We try to flip the card, but it's already flipped");
if(p1.flipCard())
System.out.println("Successful attempt! ");
else
System.out.println("Failed attempt! ");
System.out.println("Card p1 = " + p1);
System.out.println("We reset p1.");
p1.reset();
System.out.println("Card p1 = " + p1);
}
}
[code=Java]
public class MainMemory {
static Scanner input = new Scanner(System.in);
static int i=0;
static char[][] clearBoard = new char[4][4];
static char[][] letterBoard = new char[4][4];
public static void main(String[] args){
drawBoard();
}
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 void drawBoard(){
for(int row1 = 0; row1 < 4; row1++) {
System.out.println(""); // this will create a new line for each new row
for(int col1 = 0; col1 < 4; col1++) {
clearBoard[row1][col1]='.'; // this will print out the 4 row variable values
}
}
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]);
System.out.println("Please enter a column (A,B,C, or D) and row (1,2,3,or 4). Ex: A3 : ");
String userInput = input.nextLine();
userInput = userInput.toUpperCase().trim();
}
}
[code=java]
public class Board {
}
If you don't understand my answer, don't ignore it, ask a question.
To wrap your code with code tags:
<<<<<<<<<<<< THIS goes after the cod<<<<<<<<<<<<< THIS goes before the code import java.util.*; public class MainMemory { public static void main (String[] args) { } }
--- Update ---
I think i did it right?
--- Update ---
i sent off the whole problem but i have been trying to get board right but i have no idea how to start it and finish it by the way im a new bee
Good luck.
If you don't understand my answer, don't ignore it, ask a question.