help help help with arrays!please help me with the 2d arrays
Page 1 of 1
13 Replies - 952 Views - Last Post: 30 October 2008 - 03:44 AM
#1
help help help with arrays!
Posted 29 October 2008 - 08:27 PM
"Write a program that plays the memory matching game. use sixteen cards that are laid out in a 4x4 square and are labeled with pairs of numbers from 1 to 8.your program should allow the player to specify the cards that he/she would like to select trough a coordinate system"
I know you guys dont do homework, and I think thats really cool, but I really really dont know anything about arrays and I have a really bad teacher. If you guys at least can give me a direction or a pseudocode that I can use as a guide, I would really appreciate it.
Replies To: help help help with arrays!
#2
Re: help help help with arrays!
Posted 29 October 2008 - 08:39 PM
http://www.dreaminco...wtopic27806.htm
For a first project in arrays that is pretty tough... try doing some easier ones to start and get comfortable with them first then try to tackle that code
#3
Re: help help help with arrays!
Posted 29 October 2008 - 08:47 PM
markhazlett9, on 29 Oct, 2008 - 08:39 PM, said:
http://www.dreaminco...wtopic27806.htm
For a first project in arrays that is pretty tough... try doing some easier ones to start and get comfortable with them first then try to tackle that code
thanks, I've been working on that link for several hours, im doing my best
#4
Re: help help help with arrays!
Posted 29 October 2008 - 08:50 PM
isale8888, on 29 Oct, 2008 - 08:47 PM, said:
markhazlett9, on 29 Oct, 2008 - 08:39 PM, said:
http://www.dreaminco...wtopic27806.htm
For a first project in arrays that is pretty tough... try doing some easier ones to start and get comfortable with them first then try to tackle that code
thanks, I've been working on that link for several hours, im doing my best
just as a tip when you start the program, you will need a 2 dimensional array to hold the numbers. Also try to code it up when you feel comfortable and then if you're having trouble post what you have on here and we can help you out a little more. The members here always seem to want to help more when they can look at some code.
#5
Re: help help help with arrays!
Posted 29 October 2008 - 09:03 PM
isale8888, on 29 Oct, 2008 - 08:27 PM, said:
isale8888, on 29 Oct, 2008 - 08:27 PM, said:
I beleive you... How can you match a 4 X 4 array with pairs of numbers 1 to 8 ?
#6
Re: help help help with arrays!
Posted 29 October 2008 - 09:05 PM
pbl, on 29 Oct, 2008 - 09:03 PM, said:
isale8888, on 29 Oct, 2008 - 08:27 PM, said:
isale8888, on 29 Oct, 2008 - 08:27 PM, said:
I beleive you... How can you match a 4 X 4 array with pairs of numbers 1 to 8 ?
good call I didn't even see that! very confusing
#7
Re: help help help with arrays!
Posted 29 October 2008 - 09:12 PM
what will be the output for this example
int rows = 3, cols = 4;
int[][] tableArray = new int[rows][cols];
for (int rowIndex = 0; rowIndex < rows; rowIndex ++)
{
for (int colIndex = 0; colIndex < cols; colIndex ++)
{ tableArray[rowIndex][colIndex] = rowIndex * colIndex + 1; }
}
#8
Re: help help help with arrays!
Posted 29 October 2008 - 09:14 PM
to output the arrays you will need to follow the same procedure as filling them except for output
#9
Re: help help help with arrays!
Posted 29 October 2008 - 09:23 PM
import java.util.Scanner;
// memory matching game
public class Memory {
// OK wont teach you how to use a random generator lets "hard code" the values
// we will make them 3 digits long for console display
int[][] initialValue = {{100, 200, 300, 400}, {400, 500, 600, 700}, {400, 300, 200, 100}, {700, 600, 500, 400}};
// boolean to see if a value is diplayed or not
boolean[][] displayed = new boolean[4][4];
Scanner scan;
// constructor
Memory() {
boolean gameIsOver = false;
scan = new Scanner(System.in);
while(!gameIsOver) {
displayCard();
System.out.print("Enter X of card to show: ");
int x = scan.nextInt();
System.out.print("Enter Y of card to show: ");
int y = scan.nextInt();
displayed[x][y] = true;
}
}
// display the array of cards
void displayCard() {
System.out.println("The actual game:");
// display the value of the card showed or its coordinate if not showed
for(int j = 0; j < 4; j++) {
for(int i = 0; i < 4; i++) {
if(displayed[i][j])
System.out.print(" " + initialValue[i][j] + " ");
else
System.out.print(" " + i + "," + j + " ");
}
System.out.println();
}
}
public static void main(String[] arg) {
new Memory();
}
}
I haven't tried to compile and run it but it should work
#10
Re: help help help with arrays!
Posted 29 October 2008 - 09:43 PM
public class practicearray
{
public static void main(String [] args)
{
int rows = 3, cols = 4;
int[][] tableArray = new int[rows][cols];
tableArray [0][0]=20;
tableArray [0][1]=15;
tableArray [0][2]=8;
tableArray [0][3]=45;
tableArray [1][0]=40;
tableArray [1][1]= 10;
tableArray [1][2]=12;
tableArray [1][3]=85;
tableArray [2][0]= 40;
tableArray [2][1]=30;
tableArray [2][2]=78;
tableArray [2][3]=63;
for (int rowIndex = 0; rowIndex < rows; rowIndex ++)
{
for (int colIndex = 0; colIndex < cols; colIndex ++)
{ tableArray[rowIndex][colIndex] = rowIndex * colIndex + 1; }
}
}
}
outputs like a table???
so how can I make this
public class practicearray
{
public static void main(String [] args)
{
int rows = 3, cols = 4;
int[][] tableArray = new int[rows][cols];
tableArray [0][0]=20;
tableArray [0][1]=15;
tableArray [0][2]=8;
tableArray [0][3]=45;
tableArray [1][0]=40;
tableArray [1][1]= 10;
tableArray [1][2]=12;
tableArray [1][3]=85;
tableArray [2][0]= 40;
tableArray [2][1]=30;
tableArray [2][2]=78;
tableArray [2][3]=63;
for (int rowIndex = 0; rowIndex < rows; rowIndex ++)
{
for (int colIndex = 0; colIndex < cols; colIndex ++)
{ tableArray[rowIndex][colIndex] = rowIndex * colIndex + 1; }
}
}
}
outputs like a table???
#11
Re: help help help with arrays!
Posted 29 October 2008 - 09:49 PM
public class practicearray
{
public static void main(String [] args)
{
int rows = 3, cols = 4;
int[][] tableArray = new int[rows][cols];
tableArray [0][0]=20;
tableArray [0][1]=15;
tableArray [0][2]=8;
tableArray [0][3]=45;
tableArray [1][0]=40;
tableArray [1][1]= 10;
tableArray [1][2]=12;
tableArray [1][3]=85;
tableArray [2][0]= 40;
tableArray [2][1]=30;
tableArray [2][2]=78;
tableArray [2][3]=63;
for (int rowIndex = 0; rowIndex < rows; rowIndex ++)
{
for (int colIndex = 0; colIndex < cols; colIndex ++)
{ tableArray[rowIndex][colIndex] = rowIndex * colIndex + 1; }
}
}
}
outputs like a table???
#12
Re: help help help with arrays!
Posted 29 October 2008 - 10:12 PM
public class practicearray
{
public static void main(String [] args)
{
int rows = 3, cols = 4;
int[][] tableArray = new int[rows][cols];
tableArray [0][0]=20;
tableArray [0][1]=15;
tableArray [0][2]=8;
tableArray [0][3]=45;
tableArray [1][0]=40;
tableArray [1][1]= 10;
tableArray [1][2]=12;
tableArray [1][3]=85;
tableArray [2][0]= 40;
tableArray [2][1]=30;
tableArray [2][2]=78;
tableArray [2][3]=63;
for (int rowIndex = 0; rowIndex < rows; rowIndex ++)
{
for (int colIndex = 0; colIndex < cols; colIndex ++)
{ tableArray[rowIndex][colIndex] = rowIndex * colIndex + 1; }
}
}
}
outputs like a table???
#13
Re: help help help with arrays!
Posted 29 October 2008 - 10:19 PM
it is part of his forum rules
A lot of hardcoding
what was wrong with my solution ?
isale8888, on 29 Oct, 2008 - 09:43 PM, said:
public class practicearray
{
public static void main(String [] args)
{
int rows = 3, cols = 4;
int[][] tableArray = new int[rows][cols];
tableArray [0][0]=20;
tableArray [0][1]=15;
tableArray [0][2]=8;
tableArray [0][3]=45;
tableArray [1][0]=40;
tableArray [1][1]= 10;
tableArray [1][2]=12;
tableArray [1][3]=85;
tableArray [2][0]= 40;
tableArray [2][1]=30;
tableArray [2][2]=78;
tableArray [2][3]=63;
for (int rowIndex = 0; rowIndex < rows; rowIndex ++)
{
for (int colIndex = 0; colIndex < cols; colIndex ++)
{ tableArray[rowIndex][colIndex] = rowIndex * colIndex + 1; }
}
}
}
outputs like a table???
so how can I make this
public class practicearray
{
public static void main(String [] args)
{
int rows = 3, cols = 4;
int[][] tableArray = new int[rows][cols];
tableArray [0][0]=20;
tableArray [0][1]=15;
tableArray [0][2]=8;
tableArray [0][3]=45;
tableArray [1][0]=40;
tableArray [1][1]= 10;
tableArray [1][2]=12;
tableArray [1][3]=85;
tableArray [2][0]= 40;
tableArray [2][1]=30;
tableArray [2][2]=78;
tableArray [2][3]=63;
for (int rowIndex = 0; rowIndex < rows; rowIndex ++)
{
for (int colIndex = 0; colIndex < cols; colIndex ++)
{ tableArray[rowIndex][colIndex] = rowIndex * colIndex + 1; }
}
}
}
outputs like a table???
You hoo:
#14
Re: help help help with arrays!
Posted 30 October 2008 - 03:44 AM
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
for (int colIndex = 0; colIndex < cols; colIndex++) {
System.out.printf("%2d", tableArray[rowIndex][colIndex]);
if (colIndex < (cols - 1)) {
System.out.print(",");
}
}
System.out.println();
}
|
|

New Topic/Question
Reply




MultiQuote



|