diff --git a/labs/2021/02-dataflow_mvc/notebooks/.ipynb_checkpoints/components-chart-1-single-class-checkpoint.ipynb b/labs/2021/02-dataflow_mvc/notebooks/.ipynb_checkpoints/components-chart-1-single-class-checkpoint.ipynb new file mode 100644 index 000000000..a4c061828 --- /dev/null +++ b/labs/2021/02-dataflow_mvc/notebooks/.ipynb_checkpoints/components-chart-1-single-class-checkpoint.ipynb @@ -0,0 +1,571 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componentes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componente `GeometricProgression`\n", + "\n", + "Gera uma progressão geométrica a partir de um valor `inicial` e de uma `razão`." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `ISequence`\n", + "\n", + "Percorre os elementos da razão em sequência. Métodos:\n", + "* `first` - se desloca para (ou calcula) o primeiro elemento da sequência e o retorna\n", + "* `next` - se desloca para (ou calcula) o pŕoximo elemento da sequência e o retorna" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.ISequence" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISequence {\n", + " public int first();\n", + " public int next();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IGeometricProgressionProperties`\n", + "\n", + "Propriedades de uma progressão geométrica.\n", + "\n", + "Métodos `get` e `set` para as propriedades:\n", + "* `initial` - valor inicial da progressão\n", + "* `ratio` - razão da progressão" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.IGeometricProgressionProperties" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IGeometricProgressionProperties {\n", + " public int getInitial();\n", + " public void setInitial(int initial);\n", + " \n", + " public int getRatio();\n", + " public void setRatio(int ratio);\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IGeometricProgression`\n", + "\n", + "Unifica as duas interfaces anteriores." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.IGeometricProgression" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IGeometricProgression\n", + " extends ISequence, IGeometricProgressionProperties {\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Classe `GeometricProgression`\n", + "\n", + "Gera uma **Progressão Geométrica** a partir de um valor inicial (`initial`) e de uma razão (`ratio`)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.GeometricProgression" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class GeometricProgression implements IGeometricProgression {\n", + " private int initial,\n", + " ratio;\n", + " private int current;\n", + " \n", + " public GeometricProgression() {\n", + " initial = 1;\n", + " ratio = 2;\n", + " current = initial;\n", + " }\n", + " \n", + " public int getInitial() {\n", + " return initial;\n", + " }\n", + " \n", + " public void setInitial(int initial) {\n", + " this.initial = initial;\n", + " }\n", + " \n", + " public int getRatio() {\n", + " return ratio;\n", + " }\n", + " \n", + " public void setRatio(int ratio) {\n", + " this.ratio = ratio;\n", + " }\n", + " \n", + " public int first() {\n", + " current = initial;\n", + " return current;\n", + " }\n", + " \n", + " public int next() {\n", + " current *= ratio;\n", + " return current;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exemplo de uso do Componente" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Progressão Geométrica: 1, 2, 4, 8, 16, " + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "IGeometricProgression gp = new GeometricProgression();\n", + "gp.setInitial(1);\n", + "gp.setRatio(2);\n", + "System.out.print(\"Progressão Geométrica: \");\n", + "int value = gp.first();\n", + "for (int g = 1; g <= 5; g++) {\n", + " System.out.print(value + \", \");\n", + " value = gp.next();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componente `BarChart`\n", + "\n", + "Apresenta um diagrama de barras no console a partir de uma sequência de números. A sequência é produzida por um componente a ele conectado." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IChart`\n", + "\n", + "Dispara a apresentação do diagrama a partir do método `plot()`." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.IChart" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IChart {\n", + " public void plot();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IBarChartProperties`\n", + "\n", + "Propriedades para configurar um gráfico de barras.\n", + "\n", + "Métodos `get` e `set` para as propriedades:\n", + "* `filled` - define se o gráfico será preenchido\n", + "* `character` - caractere que será usado para plotar o gráfico\n", + "* `n` - número de barras que serão apresentadas" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.IBarChartProperties" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IBarChartProperties {\n", + " public boolean isFilled();\n", + " public void setFilled(boolean filled);\n", + "\n", + " public char getCharacter();\n", + " public void setCharacter(char character);\n", + "\n", + " public int getN();\n", + " public void setN(int n);\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface Requerida `IRSequence`\n", + "\n", + "Interface que requer outra interface `ISequence`. Método:\n", + "* `connect` - realiza a conexão com um componente que tem a interface ISequence" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.IRSequence" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IRSequence {\n", + " public void connect(ISequence sequence);\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Interface `IBarChart`\n", + "\n", + "Unifica as três interfaces anteriores." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.IBarChart" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IBarChart\n", + " extends IChart, IBarChartProperties, IRSequence {\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Classe `BarChart`\n", + "\n", + "Implementa a apresentação de um gráfico de barras." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr4fd108a0.BarChart" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class BarChart implements IBarChart {\n", + " private boolean filled;\n", + " private char character;\n", + " private int n;\n", + " \n", + " private ISequence sequence;\n", + " \n", + " public BarChart() {\n", + " filled = true;\n", + " character = '*';\n", + " n = 3;\n", + " }\n", + "\n", + " public boolean isFilled() {\n", + " return filled;\n", + " }\n", + "\n", + " public void setFilled(boolean filled) {\n", + " this.filled = filled;\n", + " }\n", + "\n", + " public char getCharacter() {\n", + " return character;\n", + " }\n", + "\n", + " public void setCharacter(char character) {\n", + " this.character = character;\n", + " }\n", + "\n", + " public int getN() {\n", + " return n;\n", + " }\n", + "\n", + " public void setN(int n) {\n", + " this.n = n;\n", + " }\n", + "\n", + " public void connect(ISequence sequence) {\n", + " this.sequence = sequence;\n", + " }\n", + " \n", + " public void plot() {\n", + " if (sequence != null) {\n", + " int value = sequence.first();\n", + " for (int s = 1; s <= n; s++) {\n", + " for (int v = 1; v < value; v++)\n", + " System.out.print((filled) ? character : ' ');\n", + " System.out.println(character);\n", + " value = sequence.next();\n", + " }\n", + " }\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Aplicação Exemplo\n", + "Instancia os dois componentes (progressão geométrica e gráfico de barras), os conecta e dispara o processo de plotagem no componente do gráfico de barras." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "#\n", + "##\n", + "####\n", + "########\n", + "################\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "IGeometricProgression gp = new GeometricProgression();\n", + "gp.setInitial(1);\n", + "gp.setRatio(2);\n", + "\n", + "IBarChart bc = new BarChart();\n", + "bc.setFilled(true);\n", + "bc.setCharacter('#');\n", + "bc.setN(5);\n", + "\n", + "bc.connect(gp);\n", + "bc.plot();" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Exercício do Gráfico de Segundo Grau\n", + "\n", + "## Função de segundo grau\n", + "\n", + "Escreva uma classe `SegundoGrau` cujos objetos produzam valores de uma função de segundo grau." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Plotagem de parábola\n", + "\n", + "Escreva um programa que conecte um objeto da classe `SegundoGrau` a um objeto da classe `Grafico` de forma que seja plotada uma parábola. Por conta do comportamento da classe `Grafico`, a parábola será plotada virada, ou seja eixos X e Y trocados." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "text/x-java", + "file_extension": ".java", + "mimetype": "", + "name": "Java", + "nbconverter_exporter": "", + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/labs/2021/02-dataflow_mvc/notebooks/.ipynb_checkpoints/components-chart-2-multiple-classes-checkpoint.ipynb b/labs/2021/02-dataflow_mvc/notebooks/.ipynb_checkpoints/components-chart-2-multiple-classes-checkpoint.ipynb new file mode 100644 index 000000000..9c2f9ffcf --- /dev/null +++ b/labs/2021/02-dataflow_mvc/notebooks/.ipynb_checkpoints/components-chart-2-multiple-classes-checkpoint.ipynb @@ -0,0 +1,597 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componentes com Múltiplas Classes\n", + "\n", + "# Componente `MathSequence`" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ISequence" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISequence {\n", + " public int first();\n", + " public int next();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ISeqInitialProperties" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISeqInitialProperties {\n", + " public int getInitial();\n", + " public void setInitial(int initial);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ISeqRatioProperties" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISeqRatioProperties {\n", + " public int getRatio();\n", + " public void setRatio(int ratio);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IMathSequence" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IMathSequence\n", + " extends ISequence, ISeqInitialProperties {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IMathRatioSequence" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IMathRatioSequence\n", + " extends IMathSequence, ISeqRatioProperties {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.GeometricProgression" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class GeometricProgression implements IMathRatioSequence {\n", + " private int initial,\n", + " ratio;\n", + " private int current;\n", + " \n", + " public GeometricProgression() {\n", + " initial = 1;\n", + " ratio = 2;\n", + " current = initial;\n", + " }\n", + " \n", + " public int getInitial() {\n", + " return initial;\n", + " }\n", + " \n", + " public void setInitial(int initial) {\n", + " this.initial = initial;\n", + " }\n", + " \n", + " public int getRatio() {\n", + " return ratio;\n", + " }\n", + " \n", + " public void setRatio(int ratio) {\n", + " this.ratio = ratio;\n", + " }\n", + " \n", + " public int first() {\n", + " current = initial;\n", + " return current;\n", + " }\n", + " \n", + " public int next() {\n", + " current *= ratio;\n", + " return current;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ArithmeticProgression" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ArithmeticProgression implements IMathRatioSequence {\n", + " private int initial,\n", + " ratio;\n", + " private int current;\n", + " \n", + " public ArithmeticProgression() {\n", + " initial = 1;\n", + " ratio = 1;\n", + " current = initial;\n", + " }\n", + " \n", + " public int getInitial() {\n", + " return initial;\n", + " }\n", + " \n", + " public void setInitial(int initial) {\n", + " this.initial = initial;\n", + " }\n", + " \n", + " public int getRatio() {\n", + " return ratio;\n", + " }\n", + " \n", + " public void setRatio(int ratio) {\n", + " this.ratio = ratio;\n", + " }\n", + " \n", + " public int first() {\n", + " current = initial;\n", + " return current;\n", + " }\n", + " \n", + " public int next() {\n", + " current += ratio;\n", + " return current;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.Fibonacci" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class Fibonacci implements IMathSequence {\n", + " private int initialCurrent, initialNext;\n", + " private int current, next;\n", + " \n", + " public Fibonacci() {\n", + " initialCurrent = 0;\n", + " initialNext = 1;\n", + " current = 0;\n", + " next = 1;\n", + " }\n", + " \n", + " public int getInitial() {\n", + " return initialCurrent;\n", + " }\n", + " \n", + " public void setInitial(int initial) {\n", + " current = 0;\n", + " next = 1;\n", + " while (initial > current) {\n", + " int sum = current + next;\n", + " current = next;\n", + " next = sum;\n", + " }\n", + " initialCurrent = current;\n", + " initialNext = next;\n", + " }\n", + " \n", + " public int first() {\n", + " current = initialCurrent;\n", + " next = initialNext;\n", + " return current;\n", + " }\n", + " \n", + " public int next() {\n", + " int sum = current + next;\n", + " current = next;\n", + " next = sum;\n", + " return current;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componente `BarChart`" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IChart" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IChart {\n", + " public void plot();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IRSequence" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IRSequence {\n", + " public void connect(ISequence sequence);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IBarChartProperties" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IBarChartProperties {\n", + " public boolean isFilled();\n", + " public void setFilled(boolean filled);\n", + "\n", + " public int getN();\n", + " public void setN(int n);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IBarChart" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IBarChart\n", + " extends IChart, IRSequence, IBarChartProperties {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.BarChart" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public abstract class BarChart implements IBarChart {\n", + " protected boolean filled;\n", + " protected int n;\n", + " \n", + " protected ISequence sequence;\n", + " \n", + " public BarChart() {\n", + " filled = true;\n", + " n = 3;\n", + " }\n", + "\n", + " public boolean isFilled() {\n", + " return filled;\n", + " }\n", + "\n", + " public void setFilled(boolean filled) {\n", + " this.filled = filled;\n", + " }\n", + "\n", + " public int getN() {\n", + " return n;\n", + " }\n", + "\n", + " public void setN(int n) {\n", + " this.n = n;\n", + " }\n", + "\n", + " public void connect(ISequence sequence) {\n", + " this.sequence = sequence;\n", + " }\n", + " \n", + " public abstract void plot();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ConsoleBarChart" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ConsoleBarChart extends BarChart {\n", + " private char character;\n", + " \n", + " public ConsoleBarChart() {\n", + " super();\n", + " character = '*';\n", + " }\n", + "\n", + " public char getCharacter() {\n", + " return character;\n", + " }\n", + "\n", + " public void setCharacter(char character) {\n", + " this.character = character;\n", + " }\n", + "\n", + " public void plot() {\n", + " if (sequence != null) {\n", + " int value = sequence.first();\n", + " for (int s = 1; s <= n; s++) {\n", + " if (value > 0) {\n", + " for (int v = 1; v < value; v++)\n", + " System.out.print((filled) ? character : ' ');\n", + " System.out.print(character);\n", + " }\n", + " System.out.println();\n", + " value = sequence.next();\n", + " }\n", + " }\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Aplicação Exemplo" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Geometric Progression:\n", + "*\n", + "**\n", + "****\n", + "********\n", + "****************\n", + "\n", + "Fibonacci Sequence:\n", + "*\n", + "*\n", + "**\n", + "***\n", + "*****\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "System.out.println(\"Geometric Progression:\");\n", + "\n", + "IMathRatioSequence gp = new GeometricProgression();\n", + "gp.setInitial(1);\n", + "gp.setRatio(2);\n", + "\n", + "IBarChart bcg = new ConsoleBarChart();\n", + "bcg.setFilled(true);\n", + "bcg.setN(5);\n", + "\n", + "bcg.connect(gp);\n", + "bcg.plot();\n", + "\n", + "System.out.println(\"\\nFibonacci Sequence:\");\n", + "\n", + "IMathSequence fb = new Fibonacci();\n", + "fb.setInitial(1);\n", + "\n", + "IBarChart bcf = new ConsoleBarChart();\n", + "bcf.setFilled(true);\n", + "bcf.setN(5);\n", + "\n", + "bcf.connect(fb);\n", + "bcf.plot();" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "text/x-java", + "file_extension": ".java", + "mimetype": "", + "name": "Java", + "nbconverter_exporter": "", + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/labs/2021/02-dataflow_mvc/notebooks/components-chart-1-single-class.ipynb b/labs/2021/02-dataflow_mvc/notebooks/components-chart-1-single-class.ipynb index 023410f9f..42530d7af 100644 --- a/labs/2021/02-dataflow_mvc/notebooks/components-chart-1-single-class.ipynb +++ b/labs/2021/02-dataflow_mvc/notebooks/components-chart-1-single-class.ipynb @@ -29,16 +29,16 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.ISequence" + "com.twosigma.beaker.javash.bkr4fd108a0.ISequence" ] }, - "execution_count": 2, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -65,16 +65,16 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.IGeometricProgressionProperties" + "com.twosigma.beaker.javash.bkr4fd108a0.IGeometricProgressionProperties" ] }, - "execution_count": 3, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -100,16 +100,16 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.IGeometricProgression" + "com.twosigma.beaker.javash.bkr4fd108a0.IGeometricProgression" ] }, - "execution_count": 4, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -131,16 +131,16 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.GeometricProgression" + "com.twosigma.beaker.javash.bkr4fd108a0.GeometricProgression" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -194,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -210,7 +210,7 @@ "null" ] }, - "execution_count": 7, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -247,16 +247,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.IChart" + "com.twosigma.beaker.javash.bkr4fd108a0.IChart" ] }, - "execution_count": 8, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -283,16 +283,16 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.IBarChartProperties" + "com.twosigma.beaker.javash.bkr4fd108a0.IBarChartProperties" ] }, - "execution_count": 9, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -322,16 +322,16 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.IRSequence" + "com.twosigma.beaker.javash.bkr4fd108a0.IRSequence" ] }, - "execution_count": 10, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -353,16 +353,16 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.IBarChart" + "com.twosigma.beaker.javash.bkr4fd108a0.IBarChart" ] }, - "execution_count": 11, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -384,16 +384,16 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr023d9f95.BarChart" + "com.twosigma.beaker.javash.bkr4fd108a0.BarChart" ] }, - "execution_count": 12, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -464,7 +464,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -484,7 +484,7 @@ "null" ] }, - "execution_count": 13, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } diff --git a/labs/2021/02-dataflow_mvc/notebooks/components-chart-2-multiple-classes.ipynb b/labs/2021/02-dataflow_mvc/notebooks/components-chart-2-multiple-classes.ipynb new file mode 100644 index 000000000..9c2f9ffcf --- /dev/null +++ b/labs/2021/02-dataflow_mvc/notebooks/components-chart-2-multiple-classes.ipynb @@ -0,0 +1,597 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componentes com Múltiplas Classes\n", + "\n", + "# Componente `MathSequence`" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ISequence" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISequence {\n", + " public int first();\n", + " public int next();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ISeqInitialProperties" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISeqInitialProperties {\n", + " public int getInitial();\n", + " public void setInitial(int initial);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ISeqRatioProperties" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface ISeqRatioProperties {\n", + " public int getRatio();\n", + " public void setRatio(int ratio);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IMathSequence" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IMathSequence\n", + " extends ISequence, ISeqInitialProperties {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IMathRatioSequence" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IMathRatioSequence\n", + " extends IMathSequence, ISeqRatioProperties {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.GeometricProgression" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class GeometricProgression implements IMathRatioSequence {\n", + " private int initial,\n", + " ratio;\n", + " private int current;\n", + " \n", + " public GeometricProgression() {\n", + " initial = 1;\n", + " ratio = 2;\n", + " current = initial;\n", + " }\n", + " \n", + " public int getInitial() {\n", + " return initial;\n", + " }\n", + " \n", + " public void setInitial(int initial) {\n", + " this.initial = initial;\n", + " }\n", + " \n", + " public int getRatio() {\n", + " return ratio;\n", + " }\n", + " \n", + " public void setRatio(int ratio) {\n", + " this.ratio = ratio;\n", + " }\n", + " \n", + " public int first() {\n", + " current = initial;\n", + " return current;\n", + " }\n", + " \n", + " public int next() {\n", + " current *= ratio;\n", + " return current;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ArithmeticProgression" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ArithmeticProgression implements IMathRatioSequence {\n", + " private int initial,\n", + " ratio;\n", + " private int current;\n", + " \n", + " public ArithmeticProgression() {\n", + " initial = 1;\n", + " ratio = 1;\n", + " current = initial;\n", + " }\n", + " \n", + " public int getInitial() {\n", + " return initial;\n", + " }\n", + " \n", + " public void setInitial(int initial) {\n", + " this.initial = initial;\n", + " }\n", + " \n", + " public int getRatio() {\n", + " return ratio;\n", + " }\n", + " \n", + " public void setRatio(int ratio) {\n", + " this.ratio = ratio;\n", + " }\n", + " \n", + " public int first() {\n", + " current = initial;\n", + " return current;\n", + " }\n", + " \n", + " public int next() {\n", + " current += ratio;\n", + " return current;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.Fibonacci" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class Fibonacci implements IMathSequence {\n", + " private int initialCurrent, initialNext;\n", + " private int current, next;\n", + " \n", + " public Fibonacci() {\n", + " initialCurrent = 0;\n", + " initialNext = 1;\n", + " current = 0;\n", + " next = 1;\n", + " }\n", + " \n", + " public int getInitial() {\n", + " return initialCurrent;\n", + " }\n", + " \n", + " public void setInitial(int initial) {\n", + " current = 0;\n", + " next = 1;\n", + " while (initial > current) {\n", + " int sum = current + next;\n", + " current = next;\n", + " next = sum;\n", + " }\n", + " initialCurrent = current;\n", + " initialNext = next;\n", + " }\n", + " \n", + " public int first() {\n", + " current = initialCurrent;\n", + " next = initialNext;\n", + " return current;\n", + " }\n", + " \n", + " public int next() {\n", + " int sum = current + next;\n", + " current = next;\n", + " next = sum;\n", + " return current;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Componente `BarChart`" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IChart" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IChart {\n", + " public void plot();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IRSequence" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IRSequence {\n", + " public void connect(ISequence sequence);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IBarChartProperties" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IBarChartProperties {\n", + " public boolean isFilled();\n", + " public void setFilled(boolean filled);\n", + "\n", + " public int getN();\n", + " public void setN(int n);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.IBarChart" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public interface IBarChart\n", + " extends IChart, IRSequence, IBarChartProperties {\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.BarChart" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public abstract class BarChart implements IBarChart {\n", + " protected boolean filled;\n", + " protected int n;\n", + " \n", + " protected ISequence sequence;\n", + " \n", + " public BarChart() {\n", + " filled = true;\n", + " n = 3;\n", + " }\n", + "\n", + " public boolean isFilled() {\n", + " return filled;\n", + " }\n", + "\n", + " public void setFilled(boolean filled) {\n", + " this.filled = filled;\n", + " }\n", + "\n", + " public int getN() {\n", + " return n;\n", + " }\n", + "\n", + " public void setN(int n) {\n", + " this.n = n;\n", + " }\n", + "\n", + " public void connect(ISequence sequence) {\n", + " this.sequence = sequence;\n", + " }\n", + " \n", + " public abstract void plot();\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkrcdf00f98.ConsoleBarChart" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class ConsoleBarChart extends BarChart {\n", + " private char character;\n", + " \n", + " public ConsoleBarChart() {\n", + " super();\n", + " character = '*';\n", + " }\n", + "\n", + " public char getCharacter() {\n", + " return character;\n", + " }\n", + "\n", + " public void setCharacter(char character) {\n", + " this.character = character;\n", + " }\n", + "\n", + " public void plot() {\n", + " if (sequence != null) {\n", + " int value = sequence.first();\n", + " for (int s = 1; s <= n; s++) {\n", + " if (value > 0) {\n", + " for (int v = 1; v < value; v++)\n", + " System.out.print((filled) ? character : ' ');\n", + " System.out.print(character);\n", + " }\n", + " System.out.println();\n", + " value = sequence.next();\n", + " }\n", + " }\n", + " }\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Aplicação Exemplo" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Geometric Progression:\n", + "*\n", + "**\n", + "****\n", + "********\n", + "****************\n", + "\n", + "Fibonacci Sequence:\n", + "*\n", + "*\n", + "**\n", + "***\n", + "*****\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "System.out.println(\"Geometric Progression:\");\n", + "\n", + "IMathRatioSequence gp = new GeometricProgression();\n", + "gp.setInitial(1);\n", + "gp.setRatio(2);\n", + "\n", + "IBarChart bcg = new ConsoleBarChart();\n", + "bcg.setFilled(true);\n", + "bcg.setN(5);\n", + "\n", + "bcg.connect(gp);\n", + "bcg.plot();\n", + "\n", + "System.out.println(\"\\nFibonacci Sequence:\");\n", + "\n", + "IMathSequence fb = new Fibonacci();\n", + "fb.setInitial(1);\n", + "\n", + "IBarChart bcf = new ConsoleBarChart();\n", + "bcf.setFilled(true);\n", + "bcf.setN(5);\n", + "\n", + "bcf.connect(fb);\n", + "bcf.plot();" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "text/x-java", + "file_extension": ".java", + "mimetype": "", + "name": "Java", + "nbconverter_exporter": "", + "version": "1.8.0_152-release" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": false, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}