From 21e5176c03c2d60b8de12197ac94c2b980cc5dcc Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 20 Feb 2023 10:14:11 +0000 Subject: [PATCH 1/4] Floats reformat --- .../production/poo/aula02/AverageSpeed.class | Bin 1193 -> 1221 bytes .../poo/aula02/CelciusToFahrenheit.class | Bin 1035 -> 1065 bytes .../out/production/poo/aula02/Countdown.class | Bin 1340 -> 1366 bytes .../poo/aula02/DistanceBetweenPoints.class | Bin 1440 -> 1465 bytes .../poo/aula02/EnergyToHeatWater.class | Bin 1376 -> 1410 bytes .../production/poo/aula02/Investment.class | Bin 1240 -> 1268 bytes .../out/production/poo/aula02/KmToMiles.class | Bin 1030 -> 1060 bytes .../poo/aula02/PythagoreanTheorem.class | Bin 1455 -> 1376 bytes .../poo/out/production/poo/aula02/README.md | 9 +++++++++ .../production/poo/aula02/RealNumbers.class | Bin 1363 -> 1389 bytes .../out/production/poo/utils/UserInput.class | Bin 697 -> 1039 bytes .../poo/src/aula02/AverageSpeed.java | 4 +++- .../poo/src/aula02/CelciusToFahrenheit.java | 4 +++- 1ano/2semestre/poo/src/aula02/Countdown.java | 4 ++++ .../poo/src/aula02/DistanceBetweenPoints.java | 12 +++++++----- .../poo/src/aula02/EnergyToHeatWater.java | 4 +++- 1ano/2semestre/poo/src/aula02/Investment.java | 4 +++- 1ano/2semestre/poo/src/aula02/KmToMiles.java | 4 +++- .../poo/src/aula02/PythagoreanTheorem.java | 7 +++---- .../2semestre/poo/src/aula02/RealNumbers.java | 2 ++ 1ano/2semestre/poo/src/aula02/SecsToHMS.java | 2 ++ 21 files changed, 42 insertions(+), 14 deletions(-) diff --git a/1ano/2semestre/poo/out/production/poo/aula02/AverageSpeed.class b/1ano/2semestre/poo/out/production/poo/aula02/AverageSpeed.class index b8aff85ac7d77438386396f586c718d353a153de..c4eab1f640f88d994eedc03a1b83f825b71852da 100644 GIT binary patch delta 278 zcmYL@J4*vm5QV?FZZ_FjN*aWk{{ZFTi@_w8>TT?wh}6YMyA_) ze7en2GxGk~<^7%ex~}5nMJNHGa9h8Us;OpH-muYhTo?Y1AxA@){0V4kF+}XJtB%YT zNRg=5_pdYe^Q&XZ{|RO0{9;hLDeyo#&FSbuY1w06b(Ss%94aa0iX+-OY?+Q;n}AJf Y9E*iguW=%lU3N7#k8}R#pXnKn3iKjR^@Ii98I=t@aTpw}MzmMdLFG zads^%?#!G!Gbd*oFXQBU|M>;n@=_%WV~%ZUj_lf$ZpfvbIlD=YBOjr`ClGctwZ%s4 zpRF)eV;92OhKMU+`WN7u8%;4?ditr$KT4$Hx!t%Q2mkGJQd@ZK_pIp;3G0kbyA!vV pa?gV{9P&z^fetzmKI(Z~knH9WV3!5QMTg{hx`4qa^tdi13P;jL`-d kqnWU=LNrJ*U?|Q~WyDyWIm+@(^8g z)@tXASfB$r$;|)HnVs3}OYj{8AMNK?V1v_EaBBtv9AgQ_=`lnuuC8w`9mVj$eEJo~ zT6k_7$*q8GYL0q>VRpineUI%LtO=s*g?C=sKQ!dSADj0a$Kjh-N)@oGK&Vi9gcFZ` zx?GafSy1PsFwvbOOfju3#tgF^tL85}d~rQ&`qlg56QeC{9-V|CqQV$)eJN#R=w*;T zmc>;mHTt{h1tsJdq0F34DvNn4;<%g(EUGD^ye0j$QjpVclXEy@&K%i4-Q0JqI98=# hC29OsxyQQfR!>+JCpB#(F^1Pf?(W;*ANQ4M^=J}8(j(R z#A~>B5q#ZJ@ZLXte^q_E7w0|(&#yp}%f7oep=H`Xny;v4Y51GqxX^U8Xj}I3OtA0Y zg7@s9Auuk(v403hqccOr{{)q^rDG^7EMFPYonG(y?v`<;2(%xmAw^m`qij)b# zt0KpkWQk=_+QAAnd5$`(tm)389#~g5VBHU*Qgg#%jlOItSvG&kh}#kou+5IVplDaz QL83>TsOFTPa?S;%Ke7KQwg3PC diff --git a/1ano/2semestre/poo/out/production/poo/aula02/DistanceBetweenPoints.class b/1ano/2semestre/poo/out/production/poo/aula02/DistanceBetweenPoints.class index 234bebcc128e7347ed9f4a32a456ad671649e85a..122f743f5cfc5a0859fe262978d00bbfde25584e 100644 GIT binary patch delta 644 zcmZXQ%T7~K6o$Wjdg!6;L9iectV#t5rG+CG#aa>6ih$*!6%jQgwN|XDMcd-EzCv^2 zh>1g|GJtx00OKnVAHcDRBjf6+#(~+%zt;ZO?O*G)@14*4<=6Yqz%=)(-Z!ph+N%en zl_PW-beRO`R0?3cd8aD6;gyL^$EW%cRLUV%3kmdR!51-uwsGnvCJYiIIXrL4h%B53cpg7yQ~ zkIFonoDV@sz%6)PewJ7zwrOY|_0|a|1?yq(uqbFY5?Er{;a0dIOuhJ<%yf&*eZW}X z#j{UqGUE5w=XCdlYR;3)(6WgjV{n1XO&XSRN`MQUz;AjRAv+JZfW{F?6QE z^9M|vIF-a&H5x|_{1g5F$4(9VHV&Muv-iqc`|NejC;yG_{rvm+8!$h7T&yja2XwFbHzf{Q|=d8;)&3PtF z-s(?|b5V1N%QEumPF+Si=~AZD$)sY~7;DI1_sDTgGsSiD!y4@DWm+@Ctnux+kjo84 z(tNj*=7s$yI)^2J5tPLV3EniXocQi7;erlHFfXXvbq5P9N*CrfOMzDE-=YY~x$_0L zvQPLUUGw`yBJn0YBTY_32AT{m1kCCGnZ>L<+9I24y~I%V!krj+2l0U<51Pl;_ATa0m5xsM})ipVV<8~}c6TY~@q diff --git a/1ano/2semestre/poo/out/production/poo/aula02/EnergyToHeatWater.class b/1ano/2semestre/poo/out/production/poo/aula02/EnergyToHeatWater.class index 469b9997abf032beaa3ac1d9f64b4c54cbada416..858177db34133faf36a540f499febac224c56145 100644 GIT binary patch delta 332 zcmYLDJ5Iwu6dYTQ19lpUpp@GLBtYg{@v(vM4}>5(ps~WniXb?#l?!kMpCE982nnPV z6u9FQ6jU^Hl!#e_gjSk)pP704X5HG>>-X>(fQOTT^{Lg)>we@5zuS`y8Huv9*t`nF zr4(sD==rKBI}6R1VMTP5?ys28rNYg z^Kc*D^*QZg4LWaw$Q4YY$8MIak#kc|&<5Fhov7BpC^m?NUja5z$!1&F=0uslc+Db5 zNyli9O+RA!Kf!^Wd>E6bMRYNq<+x0x7CYD_+X%3SeI}J~h67aju?ZaVRbgNWE{<54 Qbk3v3YJ|#T`gGKP02Kc|2><{9 delta 258 zcmZqTe!#_b>ff$?3=9nR41OEA-ZN?k2P76HDkK(`rY5HrDX6Aprz@nSDjZ&zUYZDE zsHPp-<*ZNuQlmOqi%EL2JJTX&b_VOs|CkIIg{>HvfJQL@Nk#@%1~wpRGue?v%-9wv z2I4U=a5C5dNggnp6=^Z38WUte#gMhzy+l9CU>#q@@@pOm>591wHUZ2bFixW zi-7gp0Zjv{VQ^+}0n*$I$qcRxZa@DX3oqxXTJR(KluE6c>}h%?gzi#?0nNE?YPsmw|DpL*e21#`;+ZN zc41{ToimTq0Y!E~suVo(H*q(KitIhV8sn9AF)~7^6$Rmb`ZYAORuktY@Tm*Ktj}}6 zVa6SC>~7V6Fsy>}w32J|mIiG1H5r`4qSP>=3Mny4nK3Nm;wRW(l7`q8Q(3~g^5w#b hSf{CTN>dqSHaXLkk!o4{7CC7vT&Qy&Uh3L#^$(H(C(i%? delta 243 zcmeyud4rSd)W2Q(7#JAr8G<)*{brPu_g5%R%t^^tNXyJi%uy&#EjqkVAthBob+Q7} zY-V-_$ITa*m>6Rm7?^;X7=R=r11kd?kaPm_^no-ZkY?4|&cL`4EbR;=LDCEioD42N zk_V!I!Ii-cEauMO0Tcmg-owBFgbWORll549c@esm7&s>Pu*ka#f%TgJtploI@MQ1; v(%cNr4BiYrKocYw%ou!u;!F%`3>pmnKo$#w1%ntv0FVW;KM<&zi6IC8m$D+} diff --git a/1ano/2semestre/poo/out/production/poo/aula02/KmToMiles.class b/1ano/2semestre/poo/out/production/poo/aula02/KmToMiles.class index 0bdc5deb5e7dc8bf6c388d03929c587a539a0ca5..0d2e8cc775c4ae7cbb33bdfc1c1d129d9111490c 100644 GIT binary patch delta 264 zcmYL@J5B;&6otQkfMFa52~0?+01Fd>K@)i?2r4LUf{vhtLo6uV0fp_9G!|@tMiUDc zz)Dz!;mlaroO|zi8vG zBzn)MpIrPml%&BSj`BVkiX2fUtB#!B&&SO*l2Mw0804yJzf*USDnmwkwahX1+LB@) Iff$?3=9nR3@#hF${9KNRnxL_6>Jq$C-*VVW@cwFo@~eTBF2b;38;nv zNHQ|8GOz(j6Ch6?NHYRyR;}#}j2pqyra%%T&A`CPUB? z4D3La3=B4to0zS65xS)q*e0K27Pl4v>(^pn0jXiI24V&VVFpbGTLwFz2@(t{Kqor@ V9VE{n%isuPu>eJ#fNGc+oB?wN89V?0 diff --git a/1ano/2semestre/poo/out/production/poo/aula02/PythagoreanTheorem.class b/1ano/2semestre/poo/out/production/poo/aula02/PythagoreanTheorem.class index 619c22438a060f3e94cebd3329810e0ff8cb9ffb..bf8e1f6e4ceac03a598a54e303571b01e2f2b13d 100644 GIT binary patch delta 349 zcmYL@J5K^p5QV?J>@IlO#Dt((W1&)5V1fo?45Hv$d_Pceg~kv~j1LNb%56;i5sC#8 z6D=(L0~R*^0xN5Ez{295bLO6zIddER(E9cJ@fpZdsp~JxIx;_2ze=S|pPGoJ(kCx> znn|X@9aQMCjdg+9Q<$N>(E%F0SB; zRKvoSu#d>R^*C`DqP*N}v|LG&goW+aw)l>@3cBEfcvX z7RxwKs37FKO|r$n_9HEBFjE?8u<)OiM4JJpw;Y$WZcg#Jpr@UjlRIQP+w2HOsZwND hvVHd1lcyM@KuMHMmQfBwxiXm`5EYTmLzz>Qe*v%IHYWf8 delta 432 zcmYLFO)mpc6g_WdI<40UNmESOu+U(kNkwE7RZ3gbM_a12r8H<%M@+lmZ@j-Dp%yd} zB$j>!TWf3FR>bC>bMLwD+(*Lyc;PVNqO3QPqxR z29L?8J?6)6j0=av8QqNEumI zZ4Cq(2qiO$uKn>lMAH9rN8l76O0U(45V{aWH&XE60zIuw5;TvdQEh|J2@{)0(=Iyp qv4sqs<|S>Ln1TTP>JBlLoD5`%ImpkC95GH^UgU{2Z`&m=341?X-AOk9 diff --git a/1ano/2semestre/poo/out/production/poo/aula02/README.md b/1ano/2semestre/poo/out/production/poo/aula02/README.md index 4a3635a..de42a52 100755 --- a/1ano/2semestre/poo/out/production/poo/aula02/README.md +++ b/1ano/2semestre/poo/out/production/poo/aula02/README.md @@ -5,5 +5,14 @@ * [Guião](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/guides/POO-2021-aula02.pdf) * [Slides](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/slides/POO_02_ControloFluxo.pdf) +### Exercise List +| Exercise Number | File Name | Exercise Number | File Name | +|-----------------|----------------------------------------------------------------------------------------------------------------------------------------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------| +| 1 | [KmToMiles.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/KmToMiles.java) | 6 | [SecsToHMS.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/SecsToHMS.java) | +| 2 | [CelciusToFahrenheit.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/CelciusToFahrenheit.java) | 7 | [DistanceBetweenPoints.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/DistanceBetweenPoints.java) | +| 3 | [EnergyToHeatWater.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/EnergyToHeatWater.java) | 8 | [PythagoreanTheorem.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/PythagoreanTheorem.java) | +| 4 | [Investment.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/Investment.java) | 9 | [Countdown.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/Countdown.java) | +| 5 | [AverageSpeed.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/AverageSpeed.java) | 10 | [RealNumbers.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/RealNumbers.java) | + --- *Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) diff --git a/1ano/2semestre/poo/out/production/poo/aula02/RealNumbers.class b/1ano/2semestre/poo/out/production/poo/aula02/RealNumbers.class index 6460fb1e67fc94e48bd5d5eee967fec73297e6d5..e2a559102e8f05e041cce55ddfd81eda740232c4 100644 GIT binary patch delta 310 zcmXAjyDo%L6otR@AO9S4&P+r?BbfwKxg-krJL7I#lBp#MQJEn^FQ^nW|08&UX-E_v zK$r;k4`q{;?WAd?{7*oj_ zwtO%_A~!t9 zPmIO{OH8QImEE*eull&Bzm-#?odJgR@Dd?ju}noAxMhV^Wfr++jdi`)!zCN?SxTI< rsV=3LQ?}GO%AByRE>BhWCDLE5oMXq~j8(xm9X5n7Li~PLu7tfmHvlH^ delta 266 zcmXAjJx&5q6otPx&*ziDsZ1_px_TE3L(Ur#L5^^w#E1)u= zZ~?Zi!!4j^#^&5}&(F>M3BSYeYrXmeTJ)FULts6X_m{w!Rx-Eos7xRap~0~!JkoZk zX*Avb2WFYsRbgs_=UBM?AE3sGwj6aDQdBmNN<`9LleJw$Y1@*v2kazo8@+KU>)*4* z9tWIqMm|l`)QgDEIp;#RB4%82rPm5fX)9+bGNB{pDDlj-m?!3m8?hW+^^3S)N#1jt M4Bf83lNQkX1HpG7#Q*>R diff --git a/1ano/2semestre/poo/out/production/poo/utils/UserInput.class b/1ano/2semestre/poo/out/production/poo/utils/UserInput.class index 4ea1b410414a752b004f3f39325f57a485388e34..9748a8df5cc2b25f2ccf58f60223ad1a0da7fb5c 100644 GIT binary patch literal 1039 zcmZvb*>2N76o&sv;5JN(f$o z<)TPj@Bq9FcZe&>KaN$pB#}JZIp6vJ3# zlhI&9`p=yxXQu6So&LJxE4_|4Q{gKWP+0p2r%7jO3|xtw9hBWXu62TZ>I{_2&W)oF z0R+r}3<9S|tux1Id|5pij`iP{;TtK*sZ3JRYSmjTG|+`aG;_8Ea-GoWzJBZsW1mIR z*1SN4YAf!FKxq@vU1$^lckxTZm?nlJwI1#Xg;LAHf(FCttz1Xw<|9 z@O@02)bkONl6?2x@7{CI54fwp8P?bD`zL^XY~NeK$U+?r6PAr8Y=L_j-9$m2CF9`u zB1+TvT41H|EDNvl^KmTDcXmS)t)eF<#kT~-hx9#tlB5C&Ih{l^fsv%sJS+CJ(=!Je zS%40EnpUAWB3YrW}#t;QH|Mz%V<}18y(&nSjGxFYI%wUn9Tn01!i%ecW>2h ziwLEw!J@WVdJL(g4jzwse00$(eSNI5(y4aQXJufGbM=z6SjR?%I--HHbrkAw(0X|M k`x!iy$~n^=alK7sr-XXt7dsWy;O|ucnF9oybkMN%59X9B!2kdN diff --git a/1ano/2semestre/poo/src/aula02/AverageSpeed.java b/1ano/2semestre/poo/src/aula02/AverageSpeed.java index 532aebb..e5fbe7a 100644 --- a/1ano/2semestre/poo/src/aula02/AverageSpeed.java +++ b/1ano/2semestre/poo/src/aula02/AverageSpeed.java @@ -18,6 +18,8 @@ public class AverageSpeed { double d2 = UserInput.getPositiveNumber(sin); double vm = (d1 + d2) / ((d1 / v1) + (d2 / v2)); - System.out.printf("Velocidade final da viagem: %fkm/h", vm); + System.out.printf("Velocidade final da viagem: %.2fkm/h", vm); + + sin.close(); } } diff --git a/1ano/2semestre/poo/src/aula02/CelciusToFahrenheit.java b/1ano/2semestre/poo/src/aula02/CelciusToFahrenheit.java index fe12735..8d4d260 100644 --- a/1ano/2semestre/poo/src/aula02/CelciusToFahrenheit.java +++ b/1ano/2semestre/poo/src/aula02/CelciusToFahrenheit.java @@ -10,6 +10,8 @@ public class CelciusToFahrenheit { Scanner sin = new Scanner(System.in); double celcius = sin.nextDouble(); double fahrenheit = 1.8*celcius+32; - System.out.printf("%fºC = %fºF", celcius, fahrenheit); + System.out.printf("%.2fºC = %.2fºF", celcius, fahrenheit); + + sin.close(); } } diff --git a/1ano/2semestre/poo/src/aula02/Countdown.java b/1ano/2semestre/poo/src/aula02/Countdown.java index a3d0919..d04bffb 100644 --- a/1ano/2semestre/poo/src/aula02/Countdown.java +++ b/1ano/2semestre/poo/src/aula02/Countdown.java @@ -11,7 +11,11 @@ public class Countdown { System.out.print("N? "); int n = sin.nextInt(); for (int i = n; i >= 0; i--) { + // If the statement before '?' is true then the expression before the ':' is used, else the expression after the ':' is used. + // In python: i + "\n" if i%10 == 0 else i + "," System.out.print(i%10 == 0 ? i + "\n" : i + ","); } + + sin.close(); } } \ No newline at end of file diff --git a/1ano/2semestre/poo/src/aula02/DistanceBetweenPoints.java b/1ano/2semestre/poo/src/aula02/DistanceBetweenPoints.java index b1c5554..af1c152 100644 --- a/1ano/2semestre/poo/src/aula02/DistanceBetweenPoints.java +++ b/1ano/2semestre/poo/src/aula02/DistanceBetweenPoints.java @@ -1,5 +1,7 @@ package aula02; +import utils.UserInput; + import java.util.Scanner; // Solução do exercício 7 @@ -8,15 +10,15 @@ public class DistanceBetweenPoints { public static void main(String[] args){ Scanner sin = new Scanner(System.in); - System.out.print("Coordenadas do ponto 1 (separadas por ','): "); - String[] p1 = sin.next().split(","); - System.out.print("Coordenadas do ponto 2 (separadas por ','): "); - String[] p2 = sin.next().split(","); + String[] p1 = UserInput.input(sin, "Coordenadas do ponto 1 (separadas por ','): ").split(","); + String[] p2 = UserInput.input(sin, "Coordenadas do ponto 2 (separadas por ','): ").split(","); double distance = Math.sqrt( Math.pow(Double.parseDouble(p1[0]) - Double.parseDouble(p2[0]), 2) + Math.pow(Double.parseDouble(p1[1]) - Double.parseDouble(p2[1]), 2)); - System.out.printf("A distância entre os dois pontos é %f", distance); + System.out.printf("A distância entre os dois pontos é %.3f", distance); + + sin.close(); } } \ No newline at end of file diff --git a/1ano/2semestre/poo/src/aula02/EnergyToHeatWater.java b/1ano/2semestre/poo/src/aula02/EnergyToHeatWater.java index dcdbef5..1892a6f 100644 --- a/1ano/2semestre/poo/src/aula02/EnergyToHeatWater.java +++ b/1ano/2semestre/poo/src/aula02/EnergyToHeatWater.java @@ -16,6 +16,8 @@ public class EnergyToHeatWater { System.out.print("Temperatura final da água (ºC)? "); double finalTemperature = sin.nextDouble(); double energy = kgOfWater * (finalTemperature - initialTemperature) * 4184; - System.out.printf("Para aquecer %fkg de água de %fºC para %fºC, serão necessários %fJ de energia.", kgOfWater, initialTemperature, finalTemperature, energy); + System.out.printf("Para aquecer %.3fkg de água de %.2fºC para %.2fºC, serão necessários %.3fJ de energia.", kgOfWater, initialTemperature, finalTemperature, energy); + + sin.close(); } } diff --git a/1ano/2semestre/poo/src/aula02/Investment.java b/1ano/2semestre/poo/src/aula02/Investment.java index 53e9844..d1957b2 100644 --- a/1ano/2semestre/poo/src/aula02/Investment.java +++ b/1ano/2semestre/poo/src/aula02/Investment.java @@ -14,6 +14,8 @@ public class Investment { System.out.print("Taxa de juro mensal (%)? "); double tax = sin.nextDouble(); double finalWallet = initialWallet * Math.pow(1 + tax/100, 3); - System.out.printf("O saldo final será de %f euros", finalWallet); + System.out.printf("O saldo final será de %.2f euros", finalWallet); + + sin.close(); } } diff --git a/1ano/2semestre/poo/src/aula02/KmToMiles.java b/1ano/2semestre/poo/src/aula02/KmToMiles.java index bd8b965..2bd5b8a 100644 --- a/1ano/2semestre/poo/src/aula02/KmToMiles.java +++ b/1ano/2semestre/poo/src/aula02/KmToMiles.java @@ -12,6 +12,8 @@ public class KmToMiles { Scanner sin = new Scanner(System.in); double km = UserInput.getPositiveNumber(sin); double miles = km / 1.609; - System.out.printf("%fkm = %f miles", km, miles); + System.out.printf("%.3fkm = %.3f miles", km, miles); + + sin.close(); } } \ No newline at end of file diff --git a/1ano/2semestre/poo/src/aula02/PythagoreanTheorem.java b/1ano/2semestre/poo/src/aula02/PythagoreanTheorem.java index c912169..4487e52 100644 --- a/1ano/2semestre/poo/src/aula02/PythagoreanTheorem.java +++ b/1ano/2semestre/poo/src/aula02/PythagoreanTheorem.java @@ -17,11 +17,10 @@ public class PythagoreanTheorem { double b = UserInput.getPositiveNumber(sin); double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); + double angDeg = Math.acos(a / c) * 180 / Math.PI; - double cossin = a / c; - double angRad = Math.acos(cossin); - double angDeg = angRad * 180 / Math.PI; + System.out.printf("O comprimento da hipotenusa é %.2f e o valor do angulo entre o cateto A e a hipotenusa é %.2f°", c, angDeg); - System.out.printf("O comprimento da hipotenusa é %f e o valor do angulo entre o cateto A e a hipotenusa é %f°", MathTools.round(c, 2), MathTools.round(angDeg, 2)); + sin.close(); } } \ No newline at end of file diff --git a/1ano/2semestre/poo/src/aula02/RealNumbers.java b/1ano/2semestre/poo/src/aula02/RealNumbers.java index 3875fb7..56d5c96 100644 --- a/1ano/2semestre/poo/src/aula02/RealNumbers.java +++ b/1ano/2semestre/poo/src/aula02/RealNumbers.java @@ -29,5 +29,7 @@ public class RealNumbers { } System.out.printf("Valor máximo: %f\nValor mínimo: %f\nMédia: %f\nTotal: %f", max, min, (float) sum/readNumbers, sum); + + sin.close(); } } \ No newline at end of file diff --git a/1ano/2semestre/poo/src/aula02/SecsToHMS.java b/1ano/2semestre/poo/src/aula02/SecsToHMS.java index 1393d99..194127c 100644 --- a/1ano/2semestre/poo/src/aula02/SecsToHMS.java +++ b/1ano/2semestre/poo/src/aula02/SecsToHMS.java @@ -17,5 +17,7 @@ public class SecsToHMS { int hours = Math.round((float) (mins / 60)); mins = mins % 60; System.out.printf("%d segundos no formato hh:mm:ss : %d:%d:%d", totalSecs, hours, mins, secs); + + sin.close(); } } \ No newline at end of file From 05a04d0717a94ed2fb748ec22511992a107ae336 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 20 Feb 2023 12:03:10 +0000 Subject: [PATCH 2/4] POO tp_codecheck added --- .../out/production/poo/aula02/SecsToHMS.class | Bin 1218 -> 1244 bytes .../poo/tp_codecheck/tp01/BankInterest.class | Bin 0 -> 1560 bytes .../poo/tp_codecheck/tp01/Table.class | Bin 0 -> 1218 bytes .../poo/tp_codecheck/tp01/Temperature.class | Bin 0 -> 1136 bytes .../poo/tp_codecheck/tp02/Strings1.md | 9 +++ .../poo/tp_codecheck/tp02/Words.class | Bin 0 -> 1376 bytes .../src/tp_codecheck/tp01/BankInterest.java | 59 ++++++++++++++++++ .../poo/src/tp_codecheck/tp01/Table.java | 28 +++++++++ .../src/tp_codecheck/tp01/Temperature.java | 29 +++++++++ .../poo/src/tp_codecheck/tp02/Strings1.md | 9 +++ .../poo/src/tp_codecheck/tp02/Words.java | 12 ++++ 11 files changed, 146 insertions(+) create mode 100644 1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/BankInterest.class create mode 100644 1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Table.class create mode 100644 1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Temperature.class create mode 100644 1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Strings1.md create mode 100644 1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Words.class create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp01/BankInterest.java create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp01/Table.java create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp01/Temperature.java create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp02/Words.java diff --git a/1ano/2semestre/poo/out/production/poo/aula02/SecsToHMS.class b/1ano/2semestre/poo/out/production/poo/aula02/SecsToHMS.class index d09e42072ad1d64840e89572b7c6949fbe3b71ef..e78b87b5aa57a371a5392c8ecafb915051124973 100644 GIT binary patch delta 248 zcmX@ad54qh)W2Q(7#JAr8GJW#RWONiF|ae3^DtO2urV^QCgSlS8)M19 z1XRZWB!MyvY(UZ)$kPYXj6j-IYdZtuMzFLEkOWCHFmN*10!bc-0tP#vB_J^e21lR> zNb@V8IyNAkHTfQMs-X5Z1~Y^SS`1v116Y)UMHw;~#K7j*LDVuhF*pPDa5Ka+xG=Z^ vO_F2?WN>3}2RclS!H2;E$YN&D0IKo?vRD|58O#~HfGk#^N^hV(CI%k>afcqq delta 222 zcmcb^d5Dwi)W2Q(7#JAr8N4=fRWLELGnh}F&h$6NjDZO#$^ax88CV(EfTRVGrw^nV zfi$bub_T|cU};Mr36f@D;AF4@k~|Ov4Au-bU@=<;JD>t3?9mrw@s`LQrV`A_G0B_G4C;$Ke diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/BankInterest.class b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/BankInterest.class new file mode 100644 index 0000000000000000000000000000000000000000..0651117c1c3623c3f78d1169dff9ab0663f1382b GIT binary patch literal 1560 zcmaJ>OK%%h7(Lgoi660XJ$0QzgHuSc3yIUv0+XbTlh|z>oTiOKO4>p+8K%kPF?OAC zp%S|agjA^@Bt%sKLISBQ*w95h@}GZe`sx9D%@?Wn0cE0dFR|7{~`0$0v|? zH-aCvCJN;LTz63*|63dU{GMwGLdAXs$p{W0^+=J*^=-%8V(w~#rS_NI@>Vr>u5Q^* z#i^V6)@T7p2p)5j=+hfsk#!E zjja{4zM#9!?<-dgeREN-Tk_m8`kXauTOeKj|Fo3Ax24N#NoG3v?%t{^^qZ5-IS~*A z2I%!wrcUhPFQ819mggrHibS)8HY(4xQ1D`LzKxYaadLTT`iwvqW6Gu3(gGoa+K^E# z7;?i}heT7>&KYADN^6t_x+{)uY|QF4R|y4Wwos`y>V|pRlCu);lyy+fE2k>Y?^iw^ za8MB7I>}RxyWs9WdLQB&_w^K4`5K6$z%|lzKoO^T3gQf=X<@K<2n8wHzEUZQir`F4 z^G7vBMOX`}=+?q2Vp_L~xE70Q@q0+@>)FBM-=S~m9-g|7XGRh|i5(o()Rap1k3U0H zg24?fc^4BB#@eR{}&($ANMZy5JnH8IEVx%KZQg5_2Mx9DEhe$aMf^x0uG`?!4@!t*KiDL z7{*mRkGF9gH*f;C_}zU-&%6BYq;6kRzw@kD!VD{!yXg8Zy19#}AzntAQ9gW$Sw?VB z@Hx&BdCBfm%n|v?@ea-rDP;N)v(NB8QuqM#L}9YNi3(9SS-(r3Gl-G<4ZK1WC$lO~ ui;T>Z`vuxm@=dn*y~^5Y`2S&8M8T4`{V3@30*OTYFL=FVb&-A^T>2LTSW8*} literal 0 HcmV?d00001 diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Table.class b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Table.class new file mode 100644 index 0000000000000000000000000000000000000000..15ff93c5afca36dddf81228ff8036cb033d9ac24 GIT binary patch literal 1218 zcmZ`(+fEZv6kVsCcFH*12BC$D77=MtsemZhiV9WR1TRSqhWKEHaoP^HQ&OfF6CaH} z`4v3yX!Jpe34VZo;UDT-6`GDC(Eo8SKHK)}8olaG1`V$IiJW@+ zUc+&{qSvs^S|)-X0b^o2@jTJFXc6=Y2sZ*lAdsg#DiEsH%L%GO0$ScpoJ;t74KWO> z7|{{OF@b?Ysu1y(tXUGsCR;FkKE&X-<;=qlQ;T9Ibtu>%dY7+hIDv$UF&!r{E)ey$ z9$EFrwpFpMCuwi%{7m}3xly$RA{DbytGkXRpd<^aoQ4UURxzm~iIhOk-@e{9y$ahz zI?^?l%0+NSAU5$>c4d05)F~EAnuc?jR*}|m9y0>{e-jm4&o0{y0d>c$HtoA4JjBu+ z{MsHF4Rg4lVqWIB_|MdG^`;MhkU%;DTjmS_u8^%j@2cb4cbc^gyV2%rtkx~Fx@I;U z$-iw>yo$3eFueMoHpzrF({Uxx&N;M4lUn2WOC%|BQkkW<*(fvNz#-1`DhPBJJ=1z} z+uUj+5Dr_r-Q+#giuGp0vTr(aI+}kxEqjMCjx@l_4+Oz$hA`Jl+@&c6WoYUH#9Jx> zEO3>_G-8pf-qtT8!(A7$xI&8z{=!|Da`PQjqgy>dU_EH`7S|P{zqlSU28!!pW3c!h z(FaO4ZjA0?CBBd2h4`y|oLW?5&{Qjk=Cce-?qimLF~yhRWK1bbO(uwkD%ri?2NGe> zM|hgG!FM@EISvgezRhW3okuq|(1Q|s;h@iFFa?EY3s~aY571)<*QhBHIj&=wavZnl zyFy+$?z#~8!HfSLH<*}DpiTEFLuAl!PhMFX9oa?yq(1u6eQo7m1jXL(uaj?h*g`kN z-T_0b7G<^=`YEFr@zEscqhNr^SEwrN9<5dKbY+pa4u&~g)Gi2^Mu3yRm4n=J^~fJq64_`@vgfi7&f&32dQQ}`@m zQjA6)z~~zp=9~FuzyJRH4ZtGGGC~MTh$x66#*jMHk9Ez`?E`IV z?~ofVL#$xhrn|rp&gOO!h$A6ER&WK%1^3Fkrps&ORre?;Q}%((y7s~`ZMWh&T(9Nh z=we6|xz#ki=AtSig>DHw3VM-d=)EL_A=(fCgqUqZ`rHW5v=8!vPapav3@8}H5W|Su zcx}|*aHGnNBh78h%xc@b*5HordJbm@H4Vzs2J&3f(kg~-+uX^^7{-W%>k3ApGIaY? zf*uUA&ELAEy0>Q$5cQ%ITm1Dyd_QALOVmvI;+SAi#`o2tI_LD;Jy$*^5HF8i2P8&BRr;#nRZakb-Ur6sVRDv7jsi!80Zk9R6&>A4nw3!f-oe@ zrp-6K+8%edb-#x_<+`C;JGx_vbLTSRR?Q~EX!*ZN<_Wf@3u=AYVBP0)LGQYAKtR2h zJX56xw+xy=238_v_w}m7?J75E&f*2b>I}SGse6vWS52XKDlkaXVmvTLvlk-O2|!FA z?ZULD--ygwqO?Gogv}sH zya&;bIa&+ETM$u+J0(L2D`bl|kIZ8tuXqxqe>Rgzrs7e8KSU2_Br{$wy>F PHWnx`MW+qA3*q@6MTq_! literal 0 HcmV?d00001 diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Strings1.md b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Strings1.md new file mode 100644 index 0000000..ea8d514 --- /dev/null +++ b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Strings1.md @@ -0,0 +1,9 @@ +# Tabela Exercício 1 de Strings + +| Question | Answer | +|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------| +| What is the length of the string below?
String str = "Java Program" | 12 | +| With str as defined above, give a call to the substring method that returns the substring "gram". | str.substring(8) | +| Use the string concatenation operator to change the string variable str to contain the string "Java Programming". | str += "ming" | +| What does the following statement sequence print?

String str = "Harry";
int n = str.length();
String mystery = str.substring(0, 1) + str.substring(n - 1, n);
System.out.println(mystery); | Hy | +| Consider the following statement sequence. If the user provides the input John Q. Public, what is printed? If an error occurs, type error.

Scanner in = new Scanner(System.in);
String first = in.next();
String last = in.next();
System.out.println(last + ", " + first); | Q., John | \ No newline at end of file diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Words.class b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Words.class new file mode 100644 index 0000000000000000000000000000000000000000..aa879395951c51270b2ed0334610ec71ca378c27 GIT binary patch literal 1376 zcmaJ>>rN9v6#k|yERLlhx|HAHlDpp&8RkRNf=;cmg) zIXD!SWawP6U0bd)gpGJkLl;AT&8aGF$IM#Xb%o!JD0(#LIK>Zlv8csR6^rAW-v=Uy(*Dv z=5Ch`+RWV?<~5i)7VwZ^@FKr0J`7q#ML6mL8tHA#n7Y(QL|RrpTV7sRMPZdpSy@;# z_dP#Pq$4R(GxTO`S8P|y2g2Xu2M%clGM>eq9QSP{HM}POrkaShd*qdbSqHA)?*_M|=N~hCZ_RAOu@1V)-Mk}$ zsf_29s+HtbhAo;)fqTal(Z; $100,000.00 2.75 % $ 0.00 + > $25,000.00 2.00 % $ 0.00 + > $10,000.00 1.00 % $ 0.00 + >= $0.00 0.00 % $ 0.00 + < $0.00 0.00 % $ 25.00 + and prints out the new balance. +*/ +public class BankInterest +{ + public static void main(String[] args) + { + // Define constants + final double HI_RATE = 2.75; + final double MD_RATE = 2.00; + final double LO_RATE = 1.00; + final double ZERO_RATE = 0.00; + final double DEB_CHG = -25.00; + + final double HI_LIMIT = 100000.00; + final double MD_LIMIT = 25000.00; + final double LO_LIMIT = 10000.00; + final double ZERO_LIMIT = 0.00; + + // Print prompt to enter a current balence + System.out.print("Enter current balance: "); + + // Read balance + Scanner in = new Scanner(System.in); + double balance = in.nextDouble(); + + // Determine interest rate (or charge) based on current balance + // to compute new balance + + // Your work here + + double newBalance; + if (balance > HI_LIMIT) + newBalance = balance*(1+HI_RATE/100); + else if (balance > MD_LIMIT) + newBalance = balance*(1+MD_RATE/100); + else if (balance > LO_LIMIT) + newBalance = balance*(1+LO_RATE/100); + else if (balance < ZERO_LIMIT) + newBalance = balance+DEB_CHG; + else + newBalance = balance; + + System.out.printf("%.2f\n", newBalance); + } +} \ No newline at end of file diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp01/Table.java b/1ano/2semestre/poo/src/tp_codecheck/tp01/Table.java new file mode 100644 index 0000000..07fc547 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp01/Table.java @@ -0,0 +1,28 @@ +package tp_codecheck.tp01; + +// Solução do exercício 3 + +public class Table { + + public static void main(String[] args) { + System.out.printf("%s | %s | %s | %s\n", "n", "Hn", "log n", "Hn - log n"); + int n = 1; + while (n <= 1000000) { + double f1 = harmonic(n); + double f2 = Math.log((double)n); + System.out.printf("%d | %.3f | %.3f | %.9f\n", n, f1, f2, f1-f2); + n *= 2; + } + } + + /** + * Computes the Harmonic number Hn = 1 + 1/2 + 1/3 + ... + 1/n. + */ + private static double harmonic(int n) { + double sum = 0; + for (int i = 1; i <= n; i++) { + sum += 1/(float)i; + } + return sum; + } +} diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp01/Temperature.java b/1ano/2semestre/poo/src/tp_codecheck/tp01/Temperature.java new file mode 100644 index 0000000..abb7a6c --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp01/Temperature.java @@ -0,0 +1,29 @@ +package tp_codecheck.tp01; + +// Solução do exercício 1 + +/* +This is a short Java program to convert +a temperature from Celsius to Fahrenheit. +*/ + +// You may want to import stuff here... + +import java.util.Scanner; + +public class Temperature { + // Create a Scanner to parse standard input: + private static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + // Put your code here + System.out.print("Celsius? "); + double celcius = sc.nextDouble(); + double fahrenheit = 1.8*celcius+32; + System.out.printf("%f C = %f F\n", celcius, fahrenheit); + + System.out.println("THE END"); + } +} + +// JMR 2023 \ No newline at end of file diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md b/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md new file mode 100644 index 0000000..ea8d514 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md @@ -0,0 +1,9 @@ +# Tabela Exercício 1 de Strings + +| Question | Answer | +|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------| +| What is the length of the string below?
String str = "Java Program" | 12 | +| With str as defined above, give a call to the substring method that returns the substring "gram". | str.substring(8) | +| Use the string concatenation operator to change the string variable str to contain the string "Java Programming". | str += "ming" | +| What does the following statement sequence print?

String str = "Harry";
int n = str.length();
String mystery = str.substring(0, 1) + str.substring(n - 1, n);
System.out.println(mystery); | Hy | +| Consider the following statement sequence. If the user provides the input John Q. Public, what is printed? If an error occurs, type error.

Scanner in = new Scanner(System.in);
String first = in.next();
String last = in.next();
System.out.println(last + ", " + first); | Q., John | \ No newline at end of file diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/Words.java b/1ano/2semestre/poo/src/tp_codecheck/tp02/Words.java new file mode 100644 index 0000000..d2fdf36 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp02/Words.java @@ -0,0 +1,12 @@ +package tp_codecheck.tp02; + +import java.util.Scanner; + +public class Words { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String word = in.next(); + word = word.charAt(word.length()-1) + word.substring(1, word.length()-1) + word.charAt(0); + System.out.println(word); + } +} From 7ccf231244a9e9a744838998596962ccd1bbb662 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:45:49 +0000 Subject: [PATCH 3/4] POO tp_codecheck finished --- .../poo/tp_codecheck/tp02/Array1.md | 23 +++++++++++++++ .../poo/tp_codecheck/tp02/NumberOfDays.class | Bin 0 -> 1536 bytes .../poo/tp_codecheck/tp02/Numbers.class | Bin 0 -> 753 bytes .../poo/src/tp_codecheck/tp02/Array1.md | 23 +++++++++++++++ .../src/tp_codecheck/tp02/NumberOfDays.java | 27 ++++++++++++++++++ .../poo/src/tp_codecheck/tp02/Numbers.java | 17 +++++++++++ 6 files changed, 90 insertions(+) create mode 100644 1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Array1.md create mode 100644 1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/NumberOfDays.class create mode 100644 1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Numbers.class create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp02/Array1.md create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp02/NumberOfDays.java create mode 100644 1ano/2semestre/poo/src/tp_codecheck/tp02/Numbers.java diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Array1.md b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Array1.md new file mode 100644 index 0000000..82c4075 --- /dev/null +++ b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Array1.md @@ -0,0 +1,23 @@ +# Exercícios de Arrays + +## Ex1 +```java +final int LENGHT = 100; +int[] a = new int[LENGHT]; +// Code for filling a ommited +for (int = 99; i >= 0; i--) +{ + System.out.print(a[i]); + if (i > 0) { System.out.print(', '); } +} +``` + +## Ex2 +```java +int[] numbers = new int[100]; +for (int k = 0; k < numbers.length; k++) +{ + numbers[k] = k + 1; +} +``` + diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/NumberOfDays.class b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/NumberOfDays.class new file mode 100644 index 0000000000000000000000000000000000000000..dbb0162226592552ba3796b68a68bf3615643728 GIT binary patch literal 1536 zcmaJ>-*4Mg6#j1G7S=&CI<|~s`6W5Upshghf$!&&2zR=`IGh`#Dk@R|{h9i964QHVv!(kXW zg}GNy8snjK`wTOl&ycG{kzP=$`h$^d$j}x2vJMVY<r5{SS~bGl@|9|g}BnQ_vO7}N-yxKyO z>>@lQq{S1=44F37W*0b9O7Kq?Ea0x44qhN-|SQG$Vx>Yi1*j9$7Oa*M0|YJ;UsC z%-5e`VPWYAr>`7gWm{d|np`%uoW=(~Ba_q2Hl0RJ%d#Ix(ATuDirUxq+Ig*A+)PqT zF8Knhz!CDQu>@3OMP#BTcIkXbt$j%!z&*_25cB9Gi|??A@3D*@>D~SXXCnf(<0kPw zu2bwT#cbjRQScBpMSnny?%@tT#1`e~lUJD}jS%K=lcXd*qNpV#{=v6Ma%^+l;@~uS fq*D~}FlC>6 zOStq52ar&e58yBO0k|X7^6cb-RBZ3g&YL&0Z+89t{M!`3Gt@LlkX0x;Qb-Hr5A0*x z@au0nMB@h!jTe() z-wlt*+Gapt!Sn)m2EMlYK9Pbsa%{hAhhFT@K_%Mvn6zU4w_=+mhqlN4%eB2(8_9XF z2QL`3>sSgj-%WO|Uhi(22ChaTa z6RD5bSrsMRM1|Q;DRMPgQ6g^PHtVc1cMa=oU;{1O;Yz|?;$;x~$aAZSYD JZ89pM`WK9}nQ#CA literal 0 HcmV?d00001 diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/Array1.md b/1ano/2semestre/poo/src/tp_codecheck/tp02/Array1.md new file mode 100644 index 0000000..82c4075 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp02/Array1.md @@ -0,0 +1,23 @@ +# Exercícios de Arrays + +## Ex1 +```java +final int LENGHT = 100; +int[] a = new int[LENGHT]; +// Code for filling a ommited +for (int = 99; i >= 0; i--) +{ + System.out.print(a[i]); + if (i > 0) { System.out.print(', '); } +} +``` + +## Ex2 +```java +int[] numbers = new int[100]; +for (int k = 0; k < numbers.length; k++) +{ + numbers[k] = k + 1; +} +``` + diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/NumberOfDays.java b/1ano/2semestre/poo/src/tp_codecheck/tp02/NumberOfDays.java new file mode 100644 index 0000000..401c3c1 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp02/NumberOfDays.java @@ -0,0 +1,27 @@ +package tp_codecheck.tp02; + +import java.util.Scanner; + +public class NumberOfDays { + public static void main(String[] args) + { + // Declare and initialize daysOfMonth + int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + Scanner in = new Scanner(System.in); + System.out.print("Month (1 - 12): "); + int month = in.nextInt(); + System.out.print("Year: "); + int year = in.nextInt(); + + if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { + // It's a leap year. Adjust the entry for February + daysOfMonth[1]+=1; + } + + // Get the number of days in the given month + int days = daysOfMonth[month-1]; + + System.out.println("Number of days: " + days); + } +} diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/Numbers.java b/1ano/2semestre/poo/src/tp_codecheck/tp02/Numbers.java new file mode 100644 index 0000000..ebaa91c --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp02/Numbers.java @@ -0,0 +1,17 @@ +package tp_codecheck.tp02; + +public class Numbers { + public static void main(String[] args) { + // Different arrays will be substituted here. + int[] values = { 3, 1, 4, 1, 5, 9 }; + int[] newValues = new int[values.length/2]; + + for (int x = 0; x < values.length; x+=2) { + newValues[x/2] = values[x]; + } + + for (int i = 0; i < newValues.length; i++) { + System.out.println(newValues[i]); + } + } +} From 3a8fb8d317651fac780be40fb5da73adc15a1ec4 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:47:57 +0000 Subject: [PATCH 4/4] README update --- 1ano/2semestre/poo/src/tp_codecheck/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 1ano/2semestre/poo/src/tp_codecheck/README.md diff --git a/1ano/2semestre/poo/src/tp_codecheck/README.md b/1ano/2semestre/poo/src/tp_codecheck/README.md new file mode 100755 index 0000000..f49dbb0 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/README.md @@ -0,0 +1,6 @@ +# Programação Orientada a Objetos +## Exercícios TP +### Resoluções para exercícios sugeridos nas aulas Teórico-Práticas + +--- +*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)