-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGraficoBarrasEmpilhadas.java
More file actions
50 lines (38 loc) · 1.26 KB
/
GraficoBarrasEmpilhadas.java
File metadata and controls
50 lines (38 loc) · 1.26 KB
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
45
46
47
48
49
50
package projeto_PI;
public class GraficoBarrasEmpilhadas {
public static void GerarGrafico(double[] valores, String[] cores, double [] valores2) {
String[] eixoY = { "Abaixo de 2000", "", "Entre 3000 e 5000", "", "Acima de 7000" };
int alturaMaxima = 5;// Arrays.stream(valores).max().orElse(0); // Altura máxima das barras
for (int linha = alturaMaxima; linha > 0; linha--) {
System.out.printf("%-19s| ", eixoY[linha - 1]);
for (int coluna = 0; coluna < valores.length; coluna++) {
if (valores2[coluna] >= linha) {
System.out.print(cores[coluna] + "### \u001B[0m " ); // Caractere para representar a barra
} else {
System.out.print(" ");
}
}
switch (linha) {
case 5:
System.out.print("| Legenda:");
break;
case 4:
System.out.print("|");
break;
case 3:
System.out.print("| \u001B[31m###\u001B[0m Queima de combustíveis fósseis");
break;
case 2:
System.out.print("| \u001B[32m###\u001B[0m Consumo de recursos naturais");
break;
case 1:
System.out.print("| \u001B[34m###\u001B[0m Não reciclagem ");
break;
default:
break;
}
System.out.println();
}
System.out.printf("%-19s %5.0f %5.0f %5.0f", "", valores[0], valores[1], valores[2]);
}
}