I'm new to Java and I'm trying to write a command line program that calculates section properties for various structural beams. The parent class Beam() has child classes Angle(), Tube(), and Rectangular(). I want the user to be able to create new beams and add the beams to a parent array like this:
Beam[] beams = new Beam[10];
Tube tb = new Tube(width, height, weight);
Angle ag = new Angle(width, height, flangeWidth);
Ideally I'd like to do something like this but I can't because the objects are different types.
beams.add(tb);
beams.add(ag);
How can I work around this to keep track of the child objects? I'd like to print all objects in the array and give the user the choice to select an object and print out calculated values for it.
Arrays, should you do something likebeams[0] = tb; beams[1] = ag?Angular/Angled,Tubular,Rectangular, orAngle,Tube,Rectanglewould be more consistent.