-
Notifications
You must be signed in to change notification settings - Fork 0
/
GanttChart.java
44 lines (33 loc) · 1.44 KB
/
GanttChart.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.ArrayList;
public class GanttChart {
GanttChart(){}
public static String printGanttChart(ArrayList<String> ganttChart){
ArrayList<String> newGanttChart = new ArrayList<String>();
newGanttChart.addAll(ganttChart);
for(int i = newGanttChart.size()-1; i>=1 ;i--){
if(newGanttChart.get(i).equals(newGanttChart.get(i-1))){
newGanttChart.remove(i);
}
}
String formattedGanttChart = newGanttChart.toString().replace(",", " | ").replace("[", "| ").replace("]", " |").trim();
return formattedGanttChart;
}
public static String printTime(ArrayList<Integer> time){
ArrayList<Integer> newTime = new ArrayList<Integer>();
// add first value
newTime.add(time.get(0));
for(int i = 1; i < time.size(); i++) {
// Compare current to previous value
if(time.get(i-1) != time.get(i)) {
newTime.add(time.get(i));
}
}
String formattedTime = newTime.toString().replace(",", " ").replace("[", " ").replace("]", " ").trim();
return formattedTime;
}
public static void showGanttChart(ArrayList<String> ganttChart, ArrayList<Integer> time){
System.out.println("\nGantt Chart: \n");
System.out.println(printGanttChart(ganttChart));
System.out.println(printTime(time)); //print time without comma and bracket
}
}