-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (java): new component examples and navigation feature
- Loading branch information
Showing
64 changed files
with
1,889 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
java/src/pt/c08componentes/s01chartseq/s01push/App0101BarChart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package pt.c08componentes.s01chartseq.s01push; | ||
|
||
import pt.c08componentes.s01chartseq.s01push.chart.BarChart; | ||
|
||
public class App0101BarChart { | ||
public static void main(String args[]) { | ||
BarChart bc1 = new BarChart(true, '#'); | ||
bc1.plot(10); | ||
bc1.plot(12); | ||
bc1.plot(8); | ||
System.out.println(); | ||
|
||
BarChart bc2 = new BarChart(false, '*'); | ||
bc2.plot(4); | ||
bc2.plot(5); | ||
bc2.plot(7); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
java/src/pt/c08componentes/s01chartseq/s01push/App0102GeoChart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package pt.c08componentes.s01chartseq.s01push; | ||
|
||
import pt.c08componentes.s01chartseq.s01push.chart.BarChart; | ||
import pt.c08componentes.s01chartseq.s01push.sequence.GeometricProgressionPre; | ||
|
||
public class App0102GeoChart { | ||
public static void main(String args[]) { | ||
BarChart bc = new BarChart(true, '#'); | ||
|
||
GeometricProgressionPre gp = new GeometricProgressionPre(1, 2, 7, bc); | ||
|
||
gp.present(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
java/src/pt/c08componentes/s01chartseq/s01push/App0103GeoChartConnect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package pt.c08componentes.s01chartseq.s01push; | ||
|
||
import pt.c08componentes.s01chartseq.s01push.chart.BarChart; | ||
import pt.c08componentes.s01chartseq.s01push.sequence.GeometricProgression; | ||
|
||
public class App0103GeoChartConnect { | ||
public static void main(String args[]) { | ||
BarChart bc = new BarChart(true, '#'); | ||
|
||
GeometricProgression gp = new GeometricProgression(1, 2, 7); | ||
|
||
gp.connect(bc); | ||
gp.present(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
java/src/pt/c08componentes/s01chartseq/s01push/App0104GeoChartMultiple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package pt.c08componentes.s01chartseq.s01push; | ||
|
||
import pt.c08componentes.s01chartseq.s01push.chart.BarChart; | ||
import pt.c08componentes.s01chartseq.s01push.sequence.GeometricProgression; | ||
|
||
public class App0104GeoChartMultiple { | ||
public static void main(String args[]) { | ||
BarChart bc1 = new BarChart(true, '#'); | ||
BarChart bc2 = new BarChart(false, '*'); | ||
|
||
GeometricProgression gp = new GeometricProgression(1, 2, 7); | ||
|
||
gp.connect(bc1); | ||
gp.present(); | ||
|
||
gp.connect(bc2); | ||
gp.present(); | ||
} | ||
} |
230 changes: 230 additions & 0 deletions
230
java/src/pt/c08componentes/s01chartseq/s01push/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
# Classes pre-Componentes / Abordagem Push | ||
|
||
*Documentação gerada a partir do Notebook Jupyter do mesmo exemplo em `notebooks/pt/s04components/s01chart/s01push.ipynb`* | ||
|
||
# Componentes `GeometricProgresion` e `BarChart` trabalhando em conjunto via Push | ||
|
||
Neste exemplo usaremos a abordagem **Push**, ou seja, o objeto da classe GeometricProgression controla todo o processo gerando a sequência de números e pede para o BarChart plotar cada valor. | ||
|
||
O `BarChart` atua de forma passiva, aguardando que lhe solicitem que plote algo. | ||
|
||
## `BarChart` Component | ||
|
||
Plota um gráfico de barras no console sob demanda. | ||
|
||
* Atributos | ||
* `filled` - define se a plotagem será preenchida; | ||
* `character` - define o caractere da plotagem. | ||
* Método | ||
* `plot()` - plota uma barra do gráfico. | ||
|
||
|
||
```Java | ||
public class BarChart { | ||
private boolean filled; | ||
private char character; | ||
|
||
public BarChart(boolean filled, char character) { | ||
this.filled = filled; | ||
this.character = character; | ||
} | ||
|
||
public void plot(int value) { | ||
for (int v = 1; v < value; v++) | ||
System.out.print((filled) ? character : ' '); | ||
System.out.println(character); | ||
} | ||
} | ||
``` | ||
|
||
## Usando objetos da classe `BarChart` | ||
|
||
Abaixo um exemplo de como objetos da classe `BarChart` podem ser usados. | ||
|
||
|
||
```Java | ||
BarChart bc1 = new BarChart(true, '#'); | ||
bc1.plot(10); | ||
bc1.plot(12); | ||
bc1.plot(8); | ||
System.out.println(); | ||
|
||
BarChart bc2 = new BarChart(false, '*'); | ||
bc2.plot(4); | ||
bc2.plot(5); | ||
bc2.plot(7); | ||
``` | ||
|
||
########## | ||
############ | ||
######## | ||
|
||
* | ||
* | ||
* | ||
|
||
## Classe `GeometricProgressionPre` | ||
|
||
Gera uma sequência de números que crescem em progressão geométrica. | ||
|
||
* Atributos | ||
* `initial` - valor inicial da sequência; | ||
* `ratio` - taxa de crescimento da progressão; | ||
* `n` - quantidade de valores na sequência; | ||
* `output` - referência para um objeto da classe `BarChart`. | ||
* Métodos | ||
* `present` - apresenta o gráfico exponencial (em conjunto com um objeto da classe `BarChart`). | ||
|
||
|
||
```Java | ||
public class GeometricProgressionPre { | ||
private int initial, | ||
ratio, | ||
n; | ||
private BarChart output; | ||
|
||
public GeometricProgressionPre(int initial, int ratio, int n, BarChart output) { | ||
this.initial = initial; | ||
this.ratio = ratio; | ||
this.n = n; | ||
this.output = output; | ||
} | ||
|
||
public void present() { | ||
if (output != null) { | ||
int value = initial; | ||
for (int s = 1; s <= n; s++) { | ||
output.plot(value); | ||
value *= ratio; | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Criando objetos associados | ||
|
||
Exemplo que cria um objeto da classe `GeometricProgression` outro da classe `BarChart`. O objeto da classe `GeometricProgression` recebe uma referência do objeto `BarChart` no construtor para se relacionar com ele. | ||
|
||
|
||
```Java | ||
BarChart bc = new BarChart(true, '#'); | ||
|
||
GeometricProgressionPre gp = new GeometricProgressionPre(1, 2, 7, bc); | ||
|
||
gp.present(); | ||
``` | ||
|
||
# | ||
## | ||
#### | ||
######## | ||
################ | ||
################################ | ||
################################################################ | ||
|
||
## Classe `GeometricProgression` | ||
|
||
No `GeometricProgressionPre` a associação com o objeto `BarChart` foi feita pelo construtor, o que limita as possibilidades de combinação, por exemplo, quando queremos conectar a mesma progressão com diversos dispositivos de saída. | ||
|
||
### Usando Conectores | ||
|
||
Uma abordagem derivada dos componentes considera usar a ideia de conector para ligar dois objetos usando o método `connect`. | ||
|
||
* Métodos adicional | ||
* `conect` - conecta dois objetos informando a um deles (`GeometricProgression`) a identidade do outro `BarChart`. | ||
|
||
|
||
```Java | ||
public class GeometricProgression { | ||
private int initial, | ||
ratio, | ||
n; | ||
private BarChart output; | ||
|
||
public GeometricProgression(int initial, int ratio, int n) { | ||
this.initial = initial; | ||
this.ratio = ratio; | ||
this.n = n; | ||
this.output = null; | ||
} | ||
|
||
public void connect(BarChart output) { | ||
this.output = output; | ||
} | ||
|
||
public void present() { | ||
if (output != null) { | ||
int value = initial; | ||
for (int s = 1; s <= n; s++) { | ||
output.plot(value); | ||
value *= ratio; | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Criando e Conectando objetos - abordagem Push | ||
|
||
Exemplo que cria um objeto da classe `GeometricProgression` outro da classe `BarChart` e os conecta através do novo método `connect`. Por ser uma abordagem Push, o `GeometricProgression` tem a referência do `BarChart` e envia (“empurra”) valores para ele. | ||
|
||
|
||
```Java | ||
BarChart bc = new BarChart(true, '#'); | ||
|
||
GeometricProgression gp = new GeometricProgression(1, 2, 7); | ||
|
||
gp.connect(bc); | ||
gp.present(); | ||
``` | ||
|
||
# | ||
## | ||
#### | ||
######## | ||
################ | ||
################################ | ||
################################################################ | ||
|
||
## Conectando o objeto `GeometricProgression` com dois objetos `BarChart` - abordagem Push | ||
|
||
Exemplo conectando o mesmo objeto da classe `GeometricProgression` com dois objetos da classe `BarChart`. | ||
|
||
```Java | ||
BarChart bc1 = new BarChart(true, '#'); | ||
BarChart bc2 = new BarChart(false, '*'); | ||
|
||
GeometricProgression gp = new GeometricProgression(1, 2, 7); | ||
|
||
gp.connect(bc1); | ||
gp.present(); | ||
|
||
gp.connect(bc2); | ||
gp.present(); | ||
``` | ||
|
||
# | ||
## | ||
#### | ||
######## | ||
################ | ||
################################ | ||
################################################################ | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
|
||
# Tarefa do Gráfico de Segundo Grau | ||
|
||
## Função de segundo grau | ||
|
||
Escreva uma classe `SecondDegree` cujos objetos produzam valores de uma função de segundo grau na abordagem **Push** e os enviem para um objeto `BarChart`. | ||
|
||
## Plotagem de parábola | ||
|
||
Escreva um programa que conecte um objeto da classe `SecondDegree` a um objeto da classe `BarChart` de forma que seja plotada uma parábola na abordagem **Push**. Por conta do comportamento da classe `BarChart`, a parábola será plotada virada, ou seja eixos X e Y trocados. |
17 changes: 17 additions & 0 deletions
17
java/src/pt/c08componentes/s01chartseq/s01push/chart/BarChart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package pt.c08componentes.s01chartseq.s01push.chart; | ||
|
||
public class BarChart { | ||
private boolean filled; | ||
private char character; | ||
|
||
public BarChart(boolean filled, char character) { | ||
this.filled = filled; | ||
this.character = character; | ||
} | ||
|
||
public void plot(int value) { | ||
for (int v = 1; v < value; v++) | ||
System.out.print((filled) ? character : ' '); | ||
System.out.println(character); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
java/src/pt/c08componentes/s01chartseq/s01push/sequence/GeometricProgression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package pt.c08componentes.s01chartseq.s01push.sequence; | ||
|
||
import pt.c08componentes.s01chartseq.s01push.chart.BarChart; | ||
|
||
public class GeometricProgression { | ||
private int initial, | ||
ratio, | ||
n; | ||
private BarChart output; | ||
|
||
public GeometricProgression(int initial, int ratio, int n) { | ||
this.initial = initial; | ||
this.ratio = ratio; | ||
this.n = n; | ||
this.output = null; | ||
} | ||
|
||
public void connect(BarChart output) { | ||
this.output = output; | ||
} | ||
|
||
public void present() { | ||
if (output != null) { | ||
int value = initial; | ||
for (int s = 1; s <= n; s++) { | ||
output.plot(value); | ||
value *= ratio; | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
java/src/pt/c08componentes/s01chartseq/s01push/sequence/GeometricProgressionPre.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pt.c08componentes.s01chartseq.s01push.sequence; | ||
|
||
import pt.c08componentes.s01chartseq.s01push.chart.BarChart; | ||
|
||
public class GeometricProgressionPre { | ||
private int initial, | ||
ratio, | ||
n; | ||
private BarChart output; | ||
|
||
public GeometricProgressionPre(int initial, int ratio, int n, BarChart output) { | ||
this.initial = initial; | ||
this.ratio = ratio; | ||
this.n = n; | ||
this.output = output; | ||
} | ||
|
||
public void present() { | ||
if (output != null) { | ||
int value = initial; | ||
for (int s = 1; s <= n; s++) { | ||
output.plot(value); | ||
value *= ratio; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.