Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed May 3, 2020
2 parents fcaab6a + 2198b51 commit 6203c96
Show file tree
Hide file tree
Showing 5 changed files with 485 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Small Challenges\n",
"# Small Challenges 1\n",
"\n",
"Tente descobrir o resultado de cada um dos programas abaixo, depois o execute para ver se confere com o que você supôs."
"Tente descobrir o resultado de cada um dos programas abaixo, depois o execute para ver se confere com o que você supôs.\n",
"\n",
"## Parte 1"
]
},
{
Expand All @@ -21,14 +23,28 @@
" public Value (int number) {\n",
" this.number = number;\n",
" }\n",
"}\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"public class Services {\n",
" public static void zero(Value x) {\n",
" x.number = 0;\n",
" }\n",
"}\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Value a = new Value(15),\n",
" b = new Value(10),\n",
" c,\n",
Expand All @@ -45,26 +61,40 @@
"System.out.println(\"d: \" + d.number);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Parte 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"public class A {\n",
" public String toString() {\n",
" return \"Eu sou A\";\n",
" }\n",
"}\n",
"\n",
" public String toString() {\n",
" return \"Eu sou A\";\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"public class B extends A {\n",
" public String toString() {\n",
" return \"Eu sou B\";\n",
" }\n",
" public String toString() {\n",
" return \"Eu sou B\";\n",
" }\n",
" \n",
" public int getIdade() {\n",
" return 45;\n",
" }\n",
" public int getIdade() {\n",
" return 45;\n",
" }\n",
"}"
]
},
Expand Down Expand Up @@ -101,6 +131,24 @@
"System.out.println(var2.getIdade());"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"B var1 = new B();\n",
"A var2 = var1;\n",
"System.out.println(var1.getIdade());"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Parte 3"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -117,14 +165,28 @@
" public String toString() {\n",
" return Integer.toString(valor);\n",
" }\n",
"}\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"public class C2 extends C1 {\n",
" public C2(int valor) {\n",
" super(valor * 2);\n",
" }\n",
"}\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"public class C3 extends C2 {\n",
" public C3(int valor) {\n",
" super(valor);\n",
Expand All @@ -133,8 +195,15 @@
" public String toString() {\n",
" return Integer.toString(valor / 2);\n",
" }\n",
"}\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"public class C4 extends C1 {\n",
" public C4(int valor) {\n",
" super(valor);\n",
Expand All @@ -143,8 +212,15 @@
" public String toString() {\n",
" return Integer.toString(valor / 2);\n",
" }\n",
"}\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"C1 cs[] = {new C1(50),\n",
" new C2(30),\n",
" new C3(40),\n",
Expand All @@ -162,14 +238,14 @@
"name": "java"
},
"language_info": {
"codemirror_mode": "java",
"codemirror_mode": "text/x-java",
"file_extension": ".java",
"mimetype": "text/x-java-source",
"mimetype": "",
"name": "Java",
"pygments_lexer": "java",
"version": "10.0.1+10-Debian-4"
"nbconverter_exporter": "",
"version": "11.0.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,50 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"com.twosigma.beaker.javash.bkrd3575b02.Operacao"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"public class Operacao {\n",
" public int soma(int n1, int n2) {\n",
" return n1 + n2;\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"25\n"
]
},
{
"data": {
"text/plain": [
"null"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"public class Operacao {\n",
" public int soma(int n1, int n2) {\n",
" return n1 + n2;\n",
" }\n",
"}\n",
"\n",
"Operacao op = new Operacao();\n",
"System.out.println(op.soma(10, 15));"
]
Expand Down Expand Up @@ -69,14 +97,14 @@
"name": "java"
},
"language_info": {
"codemirror_mode": "java",
"codemirror_mode": "text/x-java",
"file_extension": ".java",
"mimetype": "text/x-java-source",
"mimetype": "",
"name": "Java",
"pygments_lexer": "java",
"version": "10.0.1+10-Debian-4"
"nbconverter_exporter": "",
"version": "11.0.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading

0 comments on commit 6203c96

Please sign in to comment.