Advertise on Bikeforums.net



User Tag List

Results 1 to 7 of 7
  1. #1
    Senior Member FR4NCH1SE's Avatar
    Join Date
    Aug 2009
    Location
    Manassas, Virginia (NoVa)
    My Bikes
    2009 GMC DENALI (walmart bike)
    Posts
    536
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Anyone here Good at Java Programming?

    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.
    "Every Man Dies, Not Every Man Really Lives".

  2. #2
    Chepooka StupidlyBrave's Avatar
    Join Date
    Sep 2006
    Location
    South Central PA
    My Bikes
    1990 Trek 1400 7spd; 2001 Litespeed Arenberg 10 speed
    Posts
    1,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have quite a few years working in Java. I imagine there are a few others here as well.

    Shoot...

  3. #3
    Senior Member FR4NCH1SE's Avatar
    Join Date
    Aug 2009
    Location
    Manassas, Virginia (NoVa)
    My Bikes
    2009 GMC DENALI (walmart bike)
    Posts
    536
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StupidlyBrave View Post
    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.
    "Every Man Dies, Not Every Man Really Lives".

  4. #4
    Chepooka StupidlyBrave's Avatar
    Join Date
    Sep 2006
    Location
    South Central PA
    My Bikes
    1990 Trek 1400 7spd; 2001 Litespeed Arenberg 10 speed
    Posts
    1,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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("]");
    Last edited by StupidlyBrave; 11-07-09 at 07:52 PM. Reason: removed tertiary statement

  5. #5
    Senior Member FR4NCH1SE's Avatar
    Join Date
    Aug 2009
    Location
    Manassas, Virginia (NoVa)
    My Bikes
    2009 GMC DENALI (walmart bike)
    Posts
    536
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    "Every Man Dies, Not Every Man Really Lives".

  6. #6
    Chepooka StupidlyBrave's Avatar
    Join Date
    Sep 2006
    Location
    South Central PA
    My Bikes
    1990 Trek 1400 7spd; 2001 Litespeed Arenberg 10 speed
    Posts
    1,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at this.

  7. #7
    Senior Member FR4NCH1SE's Avatar
    Join Date
    Aug 2009
    Location
    Manassas, Virginia (NoVa)
    My Bikes
    2009 GMC DENALI (walmart bike)
    Posts
    536
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    "Every Man Dies, Not Every Man Really Lives".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •