Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java: Using a primitive in an identifier?

Name: Anonymous 2006-04-07 16:55

Is it possible to use a primitave value in a reference object's name?
I'm trying to set up a loop to read a list of double values from a file, and make an object for each one.  Something like:

int objectnumber = 1;
Box box-objectnumber = new Box(br.readLine());
objectnumber++;

So that I get 40 Box objects named box1 through box40.  Any ideas?  If I need to, I can just write out a hundred lines of code, but that would look stupid.  And yes, I'm a noob.

Name: Anonymous 2006-04-07 17:26

What is an array, my precious?

Name: Anonymous 2006-04-07 17:39

Box[] boxen = new Box[40];
for(int i = 0; i < 40; i++)
{
    boxen[i] = new Box(br.readLine());
}

Name: Anonymous 2006-04-07 17:51

Would this work if I'm trying to move them from one stack to another?  Im still kinda new to stacks, which is what the assignment is focusing on.

Name: Anonymous 2006-04-07 18:14

Comedy gold. Let me guess, you have to preserve the order of the objects when moving them between the stacks?

Name: Anonymous 2006-04-07 18:41

No, I have a robot that pops Boxes from a PickUpStation stack and moves it to one of 8 other stations' stacks.  Order doesn't matter.  I don't get it, why is it so funny?  Is preserving stack order some cliche project or something?  I didn't sleep last night, maybe I'm not making much sense?

Name: Anonymous 2006-04-07 19:07

Moving objects between stacks without reversing them is a good newbie exercise -- forces you to think like a programmer.

Anyway, I don't really understand what problem you have with your assignment. Are you supposed to create the stack class by yourself or do you already have one?

Name: Anonymous 2006-04-07 19:15

Both.  I'm about to test my program.  If it works, I'll post it on rapidshare or something when I get back so you can see what I'm talking about.  If it doesn't work, I'm going to dinner with some friends and will work on it later tonight.

Name: Anonymous 2006-04-07 19:21

<code>Box[] boxen = new Box[40];
for(int i = 0; i < 40; i++)
{
    boxen[39 - i] = new Box(br.readLine());
}</code>

Name: Anonymous 2006-04-07 19:22 (sage)

Box[] boxen = new Box[40];
for(int i = 0; i < 40; i++)
{
    boxen[39 - i] = new Box(br.readLine());
}

Name: Anonymous 2006-04-07 21:24

Success!  I got back from dinner, sorted out some typo-errors, ran it, and it works perfectly.  I also now have a much better grasp on stacks, which makes the assignment a good one, I guess.  And yeah, just using an array did the trick.  Not sure why I thought that wouldn't work...  Oh, well.  Thanks guys!  If anyone actually cares enough to see what the assignment was or what I did, just ask and I'll rapidshare it or something.  Otherwise I won't bother.

Name: Anonymous 2006-04-08 5:09 (sage)

>>11
RapidShare would bo cool, I'd like to see the finished program if you don't mind

Name: Anonymous 2006-04-09 15:18

>>11
Also note that you can create an array this way too:
Box boxen[] = {new Box(br.readLine(), new Box(br.readLine(),...new Box(br.readLine()};

Name: Anonymous 2006-04-09 18:41 (sage)

>>13
And yes, I forgot a ')' in my copypasta.

Name: Anonymous 2006-04-21 6:26

http://rapidshare.de/files/18556662/Project.tar.bz2.html

>>12
Sorry it took so long to reply.  Went to the beach for a week and then got swamped with all the stuff I missed.  I know it sucks, but I did end up with an A for it, even though I only worked on it that one night.

Name: Anonymous 2006-04-23 18:56 (sage)

>>15
Thanks :D

Name: Anonymous 2006-11-14 21:10

jarbur

Name: Anonymous 2010-09-21 13:21

Don't use Java.

Name: PHP FAGGOT 2010-09-21 14:42


$a = "sex";
$$a = 95;
print $sex; // 95


VALID PHP CODE

Name: Anonymous 2010-09-21 15:24

>>18
Why the fuck did you have to bump THE SHITTIEST threads of 2006?  Are they really better than reading /prog/ with a magnifying glass?

Name: Anonymous 2010-09-21 16:23

>>20
At least it's better than 50 threads of opiates.

Name: Anonymous 2010-09-21 16:34

Holy shit, [spoiler]/prague/[spoiler] was NICE at one point in time!
Towards a beginner learning Java too!

Name: Anonymous 2011-02-04 12:54

Name: Anonymous 2011-12-30 3:28

ENTERPRISE BUMP

Don't change these.
Name: Email:
Entire Thread Thread List