Is there a better way to represent this menu structure in Java? I think the problem is that I’m declaring an array that contains Strings and arrays – not possible right?
String[][][] menu = {
"1. Select Store",
{
"1. Manage Stock",
{
"1. Buy More",
"2. Steal It"
},
"2. Fire Employee",
"3. Exit"
},
"2. List Stores",
"3. Exit"
};
So I tried this:
String[][][] menu = {
{"1. Select Store"},
{
{"1. Manage Stock"},
{
{"1. Buy More"},
{"2. Steal It"}
},
{"2. Fire Employee"},
{"3. Exit"}
},
{"2. List Stores"},
{"3. Exit"}
};
Still no better.
You need to make everything is at least a three deep array with one string in it:
Possibly a bit more complex than you are wanting but if each menu item knows about its sub menus then it is easier to keep track of it all. This will print out your example with similar indents.