Cycling and bicycle discussion forums. 
   Click here to join our community Log in to access your Control Panel  


Go Back   > >

Foo Off-Topic chit chat with no general subject.

User Tag List

Reply
 
Thread Tools Search this Thread
Old 11-07-09, 06:24 PM   #1
FR4NCH1SE
Senior Member
Thread Starter
 
FR4NCH1SE's Avatar
 
Join Date: Aug 2009
Location: Manassas, Virginia (NoVa)
Bikes: 2009 GMC DENALI (walmart bike)
Posts: 537
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
FR4NCH1SE is offline   Reply With Quote
Old 11-07-09, 06:46 PM   #2
StupidlyBrave 
Chepooka
 
StupidlyBrave's Avatar
 
Join Date: Sep 2006
Location: South Central PA
Bikes: 1990 Trek 1400 7spd; 2001 Litespeed Arenberg 10 speed
Posts: 1,167
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
I have quite a few years working in Java. I imagine there are a few others here as well.

Shoot...
StupidlyBrave is offline   Reply With Quote
Old 11-07-09, 07:14 PM   #3
FR4NCH1SE
Senior Member
Thread Starter
 
FR4NCH1SE's Avatar
 
Join Date: Aug 2009
Location: Manassas, Virginia (NoVa)
Bikes: 2009 GMC DENALI (walmart bike)
Posts: 537
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
FR4NCH1SE is offline   Reply With Quote
Old 11-07-09, 07:47 PM   #4
StupidlyBrave 
Chepooka
 
StupidlyBrave's Avatar
 
Join Date: Sep 2006
Location: South Central PA
Bikes: 1990 Trek 1400 7spd; 2001 Litespeed Arenberg 10 speed
Posts: 1,167
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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
StupidlyBrave is offline   Reply With Quote
Old 11-07-09, 07:56 PM   #5
FR4NCH1SE
Senior Member
Thread Starter
 
FR4NCH1SE's Avatar
 
Join Date: Aug 2009
Location: Manassas, Virginia (NoVa)
Bikes: 2009 GMC DENALI (walmart bike)
Posts: 537
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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.
FR4NCH1SE is offline   Reply With Quote
Old 11-07-09, 08:04 PM   #6
StupidlyBrave 
Chepooka
 
StupidlyBrave's Avatar
 
Join Date: Sep 2006
Location: South Central PA
Bikes: 1990 Trek 1400 7spd; 2001 Litespeed Arenberg 10 speed
Posts: 1,167
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Look at this.
StupidlyBrave is offline   Reply With Quote
Old 11-07-09, 08:14 PM   #7
FR4NCH1SE
Senior Member
Thread Starter
 
FR4NCH1SE's Avatar
 
Join Date: Aug 2009
Location: Manassas, Virginia (NoVa)
Bikes: 2009 GMC DENALI (walmart bike)
Posts: 537
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(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?
FR4NCH1SE is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -6. The time now is 08:07 AM.