Skip to content

Commit c5f19f2

Browse files
committed
feat (class/relationship): resolution of the exercise
1 parent 8da298f commit c5f19f2

File tree

3 files changed

+155
-14
lines changed

3 files changed

+155
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Todos os exemplos no diretório `notebook` são preparados para o ambiente Jupyt
88
## Abrir branch específico em uma instância do [binderhub](https://github.com/jupyterhub/binderhub)
99

1010
* Última versão testada e estável:
11-
[![launch @ mybinder.org][badge-jupyterlab-mybinder-org]](https://mybinder.org/v2/gh/santanche/java2learn/v1.1.2?urlpath=lab)
11+
[![launch @ mybinder.org][badge-jupyterlab-mybinder-org]](https://mybinder.org/v2/gh/santanche/java2learn/v1.1.3?urlpath=lab)
1212

1313
* Última versão disponível:
1414
[![launch @ mybinder.org][badge-jupyterlab-mybinder-org]](https://mybinder.org/v2/gh/santanche/java2learn/master?urlpath=lab)
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "featured-appendix",
6+
"metadata": {},
7+
"source": [
8+
"# Primeiro Tabuleiro"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "juvenile-silicon",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"data": {
19+
"text/plain": [
20+
"com.twosigma.beaker.javash.bkr0f150d79.Peca"
21+
]
22+
},
23+
"execution_count": 1,
24+
"metadata": {},
25+
"output_type": "execute_result"
26+
}
27+
],
28+
"source": [
29+
"public class Peca {\n",
30+
" Peca esquerda = null,\n",
31+
" direita = null;\n",
32+
"\n",
33+
" public void pecaEsquerda(Peca pc) {\n",
34+
" esquerda = pc;\n",
35+
" }\n",
36+
" \n",
37+
" public void pecaDireita(Peca pc) {\n",
38+
" direita = pc;\n",
39+
" }\n",
40+
" \n",
41+
" public String mostra() {\n",
42+
" return \"#\";\n",
43+
" }\n",
44+
"}"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": 2,
50+
"id": "patent-humanitarian",
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"data": {
55+
"text/plain": [
56+
"com.twosigma.beaker.javash.bkr0f150d79.Tabuleiro"
57+
]
58+
},
59+
"execution_count": 2,
60+
"metadata": {},
61+
"output_type": "execute_result"
62+
}
63+
],
64+
"source": [
65+
"public class Tabuleiro {\n",
66+
" Peca tab[];\n",
67+
" \n",
68+
" public Tabuleiro() {\n",
69+
" tab = new Peca[10];\n",
70+
" }\n",
71+
" \n",
72+
" public void inserePeca(Peca pc, int posicao) {\n",
73+
" if (posicao < tab.length) {\n",
74+
" tab[posicao] = pc;\n",
75+
" if (posicao > 0) {\n",
76+
" pc.pecaEsquerda(tab[posicao-1]);\n",
77+
" if (tab[posicao-1] != null)\n",
78+
" tab[posicao-1].pecaDireita(pc);\n",
79+
" } else\n",
80+
" pc.pecaEsquerda(null);\n",
81+
" if (posicao < tab.length - 1) {\n",
82+
" pc.pecaDireita(tab[posicao+1]);\n",
83+
" if (tab[posicao+1] != null)\n",
84+
" tab[posicao+1].pecaEsquerda(pc);\n",
85+
" } else\n",
86+
" pc.pecaDireita(null);\n",
87+
" }\n",
88+
" }\n",
89+
" \n",
90+
" public String mostra() {\n",
91+
" String result = \"\";\n",
92+
" for (int t = 0; t < tab.length; t++)\n",
93+
" result += (tab[t] == null) ? \".\" : tab[t].mostra();\n",
94+
" return result;\n",
95+
" }\n",
96+
"}"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 3,
102+
"id": "comparative-calibration",
103+
"metadata": {},
104+
"outputs": [
105+
{
106+
"name": "stdout",
107+
"output_type": "stream",
108+
"text": [
109+
".#.##..###\n"
110+
]
111+
},
112+
{
113+
"data": {
114+
"text/plain": [
115+
"null"
116+
]
117+
},
118+
"execution_count": 3,
119+
"metadata": {},
120+
"output_type": "execute_result"
121+
}
122+
],
123+
"source": [
124+
"Tabuleiro tabl = new Tabuleiro();\n",
125+
"int posicoes[] = {1, 3, 4, 7,8, 9};\n",
126+
"for (int p = 0; p < posicoes.length; p++)\n",
127+
" tabl.inserePeca(new Peca(), posicoes[p]);\n",
128+
"System.out.println(tabl.mostra());"
129+
]
130+
}
131+
],
132+
"metadata": {
133+
"kernelspec": {
134+
"display_name": "Java",
135+
"language": "java",
136+
"name": "java"
137+
},
138+
"language_info": {
139+
"codemirror_mode": "text/x-java",
140+
"file_extension": ".java",
141+
"mimetype": "",
142+
"name": "Java",
143+
"nbconverter_exporter": "",
144+
"version": "1.8.0_121"
145+
}
146+
},
147+
"nbformat": 4,
148+
"nbformat_minor": 5
149+
}

notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/primeiro-tabuleiro.ipynb renamed to notebooks/pt/c02oo-java/s03relacionamento/s04tabuleiro/s02resolucao/primeiro-tabuleiro.ipynb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
{
44
"cell_type": "code",
55
"execution_count": 1,
6-
"id": "adjusted-astrology",
6+
"id": "absent-motorcycle",
77
"metadata": {},
88
"outputs": [
99
{
1010
"data": {
1111
"text/plain": [
12-
"com.twosigma.beaker.javash.bkr2da291e3.Peca"
12+
"com.twosigma.beaker.javash.bkr010bf114.Peca"
1313
]
1414
},
1515
"execution_count": 1,
@@ -39,13 +39,13 @@
3939
{
4040
"cell_type": "code",
4141
"execution_count": 2,
42-
"id": "stunning-bailey",
42+
"id": "twelve-reality",
4343
"metadata": {},
4444
"outputs": [
4545
{
4646
"data": {
4747
"text/plain": [
48-
"com.twosigma.beaker.javash.bkr2da291e3.Tabuleiro"
48+
"com.twosigma.beaker.javash.bkr010bf114.Tabuleiro"
4949
]
5050
},
5151
"execution_count": 2,
@@ -91,7 +91,7 @@
9191
{
9292
"cell_type": "code",
9393
"execution_count": 3,
94-
"id": "billion-catalog",
94+
"id": "patient-background",
9595
"metadata": {},
9696
"outputs": [
9797
{
@@ -119,14 +119,6 @@
119119
" tabl.inserePeca(new Peca(), posicoes[p]);\n",
120120
"System.out.println(tabl.mostra());"
121121
]
122-
},
123-
{
124-
"cell_type": "code",
125-
"execution_count": null,
126-
"id": "hybrid-vertex",
127-
"metadata": {},
128-
"outputs": [],
129-
"source": []
130122
}
131123
],
132124
"metadata": {

0 commit comments

Comments
 (0)