create objects in an array from integers...?
in
Programming Questions
•
2 years ago
Hi all, i'm a bit stuck hope you can help.
say I have a parent class of:
- "Primitive" which is passed a float of where it appears on the X axis.
it has 5 different child classes which might be created like this:
- Sphere(10)
- Cylinder(20)
- Cone(30)
- Cube(40)
- Torus(50)
I have an want to declare another object called "Group" which is among other things contains a Primitive[] array.
Group(1,2,1,3,4,3)
which will give me a group containing from x position
group[0] = new Sphere()
group[1] = new Cylinder()
group[2] = new Sphere()
group[3] = new Cone()
group[4] = new Cube()
group[5] = new Torus()
any ideas how I might take the series of ints from the constructor of the Group object and pass them to create a corresponding object in the Primitive array....?
From a string on 10 letters would be even better but I'd settle for just a conceptual way of doing this that wouldn't involve a massive number of IF's cos I'm sure there's a more simple efficient way of doing it
At the moment i have the numbers passed from the constructor into an int array but I don't know what to do with them from there...?
Hope you can help and that this isn't all a bit badly explained
Dave
1
