I am having some issues even starting with this task so I thought some of you might help. Basically I am given a .csv file like in the example below and it should be displayed like int the example output.
Here is the content of the .csv file:
The first is the ID, Second menuname, third is Parent ID (if its a number it should be that number's child), and if Hidden is true it should not display.
ID;MenuName;ParentID;isHidden;LinkURL
1;Company;NULL;False;/company
2;About Us;1;False;/company/aboutus
3;Mission;1;False;/company/mission
4;Team;2;False;/company/aboutus/team
5;Client 2;10;False;/references/client2
6;Client 1;10;False;/references/client1
7;Client 4;10;True;/references/client4
8;Client 5;10;True;/references/client5
10;References;NULL;False;/references
Here is the output:
. Company
.... About Us
....... Team
.... Mission
. References
.... Client 1
.... Client 2
- The menu items should be indented depending on the parent they belong under.
- Some items are hidden, and should not be presented
- The items should be ordered alphabetically
Can you guys point me out how to start and what data structures to use (I was having in mind Stack) but I am not sure. Thanks!
Here is my code so far.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Stack;
public class Main {
static void Function() {
}
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader csvReader = new BufferedReader(new FileReader("Navigation.csv"));
String row;
int parent_id = 0;
Stack stack = new Stack();
while ((row = csvReader.readLine()) != null) {
String[] data = row.split(";");
stack.push(row);
for(int i=0; i<4; i++){
System.out.print(data[i] + " ");
if(data[2].equals("NULL")){
parent_id = Integer.parseInt(data[0]);
}
}
System.out.println(parent_id);
}
csvReader.close();
for(int i=0;i<10;i++){
System.out.println(stack.pop());
}
}
}