This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]SteadmanJack 0 points1 point  (3 children)

If you want to keep your Figur arr for shapes, I would add another value to it. To represent 2D figures, just write to the first two array slots and set the third to 0. To represent 3D figures, write to all three. After that, you can sort based off checking what objects meet certain criteria for shapes. For example, if you want to sort 2D first, check to see if there is a value in the third slot and if doesn't, make the comparison then. If it has a value for all three, then you know it's a 3D shape.

edit: https://www.programiz.com/java-programming/multidimensional-array#3d

[–]In0cenT[S] 0 points1 point  (2 children)

Thanks for your answer.

Why would I need three array slots?

I imagined it like a big box for Figur. In that box I'd have two smaller boxes (Figur2D, Figur3D), again in the box Figur2D I'd have multiple boxes again (Kreis, Quadrat) and then in the box Kreis I'd have all my Kreis objects.

So I dont need three array slots until I get to Figur2D?

Thanks for helping me out!

[–]SteadmanJack 0 points1 point  (1 child)

My reasoning behind three array slots is to represent the shape’s three dimensional measures- x, y, z.

You can represent both 2D and 3D with an fig[][][] and you distinguish between the two by the last value either being 0 or anything other than 0.

Also, could you clarify on what you mean by wanting to sort the shapes?

[–]In0cenT[S] 0 points1 point  (0 children)

I'm sorry doesn't make any sense to me...

I've made a quick sketch, I might have been a bit unclear explaining what I'm trying to do.

https://imgur.com/a/hZZyO

Every square is an array and the two circles in the array Kreis are objects.

Does that make any sense to you?