diff --git a/README.md b/README.md index 845eab4..0a0b7a1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Todos os exemplos no diretório `notebook` são preparados para o ambiente Jupyt ## Abrir branch específico em uma instância do [binderhub](https://github.com/jupyterhub/binderhub) * Última versão testada e estável: - [![launch @ mybinder.org][badge-jupyterlab-mybinder-org]](https://mybinder.org/v2/gh/santanche/java2learn/v1.1.2?urlpath=lab) + [![launch @ mybinder.org][badge-jupyterlab-mybinder-org]](https://mybinder.org/v2/gh/santanche/java2learn/v1.1.3?urlpath=lab) * Última versão disponível: [![launch @ mybinder.org][badge-jupyterlab-mybinder-org]](https://mybinder.org/v2/gh/santanche/java2learn/master?urlpath=lab) diff --git a/notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/s01tarefa/primeiro-tabuleiro.ipynb b/notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/s01tarefa/primeiro-tabuleiro.ipynb new file mode 100644 index 0000000..9754931 --- /dev/null +++ b/notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/s01tarefa/primeiro-tabuleiro.ipynb @@ -0,0 +1,149 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "featured-appendix", + "metadata": {}, + "source": [ + "# Primeiro Tabuleiro" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "juvenile-silicon", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr0f150d79.Peca" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class Peca {\n", + " Peca esquerda = null,\n", + " direita = null;\n", + "\n", + " public void pecaEsquerda(Peca pc) {\n", + " esquerda = pc;\n", + " }\n", + " \n", + " public void pecaDireita(Peca pc) {\n", + " direita = pc;\n", + " }\n", + " \n", + " public String mostra() {\n", + " return \"#\";\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "patent-humanitarian", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "com.twosigma.beaker.javash.bkr0f150d79.Tabuleiro" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "public class Tabuleiro {\n", + " Peca tab[];\n", + " \n", + " public Tabuleiro() {\n", + " tab = new Peca[10];\n", + " }\n", + " \n", + " public void inserePeca(Peca pc, int posicao) {\n", + " if (posicao < tab.length) {\n", + " tab[posicao] = pc;\n", + " if (posicao > 0) {\n", + " pc.pecaEsquerda(tab[posicao-1]);\n", + " if (tab[posicao-1] != null)\n", + " tab[posicao-1].pecaDireita(pc);\n", + " } else\n", + " pc.pecaEsquerda(null);\n", + " if (posicao < tab.length - 1) {\n", + " pc.pecaDireita(tab[posicao+1]);\n", + " if (tab[posicao+1] != null)\n", + " tab[posicao+1].pecaEsquerda(pc);\n", + " } else\n", + " pc.pecaDireita(null);\n", + " }\n", + " }\n", + " \n", + " public String mostra() {\n", + " String result = \"\";\n", + " for (int t = 0; t < tab.length; t++)\n", + " result += (tab[t] == null) ? \".\" : tab[t].mostra();\n", + " return result;\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "comparative-calibration", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ".#.##..###\n" + ] + }, + { + "data": { + "text/plain": [ + "null" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Tabuleiro tabl = new Tabuleiro();\n", + "int posicoes[] = {1, 3, 4, 7,8, 9};\n", + "for (int p = 0; p < posicoes.length; p++)\n", + " tabl.inserePeca(new Peca(), posicoes[p]);\n", + "System.out.println(tabl.mostra());" + ] + } + ], + "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_121" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/primeiro-tabuleiro.ipynb b/notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/s02resolucao/primeiro-tabuleiro.ipynb similarity index 90% rename from notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/primeiro-tabuleiro.ipynb rename to notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/s02resolucao/primeiro-tabuleiro.ipynb index 157072a..9c58fd6 100644 --- a/notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/primeiro-tabuleiro.ipynb +++ b/notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/s02resolucao/primeiro-tabuleiro.ipynb @@ -3,13 +3,13 @@ { "cell_type": "code", "execution_count": 1, - "id": "adjusted-astrology", + "id": "absent-motorcycle", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr2da291e3.Peca" + "com.twosigma.beaker.javash.bkr010bf114.Peca" ] }, "execution_count": 1, @@ -39,13 +39,13 @@ { "cell_type": "code", "execution_count": 2, - "id": "stunning-bailey", + "id": "twelve-reality", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "com.twosigma.beaker.javash.bkr2da291e3.Tabuleiro" + "com.twosigma.beaker.javash.bkr010bf114.Tabuleiro" ] }, "execution_count": 2, @@ -91,7 +91,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "billion-catalog", + "id": "patient-background", "metadata": {}, "outputs": [ { @@ -119,14 +119,6 @@ " tabl.inserePeca(new Peca(), posicoes[p]);\n", "System.out.println(tabl.mostra());" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "hybrid-vertex", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {