Foo - Anyone here Good at Java Programming?

Bikeforums.net is a forum about nothing but bikes. Our community can help you find information about hard-to-find and localized information like bicycle tours, specialties like where in your area to have your recumbent bike serviced, or what are the best bicycle tires and seats for the activities you use your bike for.




FR4NCH1SE
11-07-09, 05:24 PM
I am a novice at Java and I am taking a class on it right now, it was steady and easy in the beginning and now its getting tough.Anyone here can give me some help? I am not looking for answers to programs, I am just looking for some help on the logic, because I dont have experiance at it, I am very weak at understanding things. I do however understand logic building, methods, arrays,variables. I have taken PHP, TOO.


StupidlyBrave
11-07-09, 05:46 PM
I have quite a few years working in Java. I imagine there are a few others here as well.

Shoot...

FR4NCH1SE
11-07-09, 06:14 PM
I have quite a few years working in Java. I imagine there are a few others here as well.

Shoot...

THanks pal this means the world for me,

so as far as logic is concerned, I am building a Java Game, its basically a grid of 64 squares that resemble cards, in each grid there lies 1 of 4 shapes, circle,square,triangle,hexagon.

I have most of the code done for it, all I need to do is adjust 1 thing.

That is, the population of the random shapes.

currently my code works by first creating a two dimensional array that take int values, and I made a method that populates it like the following.
private Random random = new Random();
private int[][] randShape = new int [8][8];

for(int row = 0; row < 8 ; row++){
for(int col = 0; col < 8 ; col++){
randShape[row][col] = random.nextInt(4) +1;
**
**


yep that works for my code and how I was instructed to populate it, this weeks assignment has other thing and adds what I am working on right now.

this weeks requirement is now to change the way I populate my 2D array of random numbers (shapes)

now I have have a even number of shapes (1s,2s,3s,4s) in my 2D Array.

clearly the way I populated my 2D array in the past (see above) didn't keep track of even number of shapes.(numbers)


So that is what I have to do, I got some good logic up just need the game ender(the last part)

so what I did to have even number of shapes(1,2,3,4)

I made 2, 1D arrays named arrayA and arrayB both of size 32 or private int[] arrayA = int [32] , private int[] arrayB = int [32]


I run a for loop to populate the arrayA with same logic as above except on a 1D array, (nextInt(4)+1)
after that in the same loop I also insert arrayA[counter] into arrayB[counter]
ex. arrayB[x] = arrayA[x];

that means in a for loop create a random number from 1-4 take that random value that now is in array[x] and put that into arrayB[x], so basically copying the value to a 2nd array, and which also means I have a even value of the same number.

now that that done, I did another thing which I called "shuffling" the 2nd array, arrayB so that it isn't static. the way I did it, is complicated to explain.

so comes to where I am stuck, I have 2 populated 1D arrays(arrayA and arrayB), that I know want to insert into randShape 2D array of [8][8]. But I dont know how to. I know I can use brackets and insert them that way but that is to much of a pain, I want a logical way to insert them.


StupidlyBrave
11-07-09, 06:47 PM
I don't see how your refinement guarantees that all four types have the same amount in the end.

Try this with the original program:

1) when you are creating the Random object, pass a somewhat unique seed. Most people use System.currentTimeMillis();
2) Create a counter array of int[4] and use it to keep track of your results. The random number generator is supposed to yield uniform distribution.
int ctr[4];
...
int x = random.nextInt(4) +1;
randShape[row][col] = x;
ctr[x]++;
...

System.out.print("Counters: ["
for( int i=0; i<ctr.length; i++){
System.out.print(ctr[i]);
if( i < ctr.length ) {
System.out.print(",");
**
**
System.out.println("]");

FR4NCH1SE
11-07-09, 06:56 PM
umm maybe I wasn't clear enough, I have my own way of showing the shapes, I am going to draw the shapes using graphicComponent the 2D array of randShape which has the random 1-4 numbers are then used in a case statement to generate the shape based on which number it is, 1-4.


My question to you, is how can I populate a 2D array with 2 1D arrays. That is my question.

StupidlyBrave
11-07-09, 07:04 PM
Look at this (http://java.sun.com/javase/6/docs/api/java/lang/System.html#arraycopy%28java.lang.Object,%20int,%20java.lang.Object,%20int,%20int%29).

FR4NCH1SE
11-07-09, 07:14 PM
you my friend are a beast, thank you so much, this is exactly what I needed, but like any other full time worker / full time student, I rush things and not read through the API!!! haha. API always solves my problems, I just get to fussy to check the API, plus I am novice at Java, give me a good year of this under my belt and I could do alot better than I am doing now, but this is a University Course I need to do in 16 weeks!!! I am studying to be a DBA, do you think I should learn more Programming, Like Java?