diff --git a/1ano/2semestre/poo/out/production/poo/aula02/AverageSpeed.class b/1ano/2semestre/poo/out/production/poo/aula02/AverageSpeed.class index b8aff85..c4eab1f 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/AverageSpeed.class and b/1ano/2semestre/poo/out/production/poo/aula02/AverageSpeed.class differ diff --git a/1ano/2semestre/poo/out/production/poo/aula02/CelciusToFahrenheit.class b/1ano/2semestre/poo/out/production/poo/aula02/CelciusToFahrenheit.class index b4898f0..fd19361 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/CelciusToFahrenheit.class and b/1ano/2semestre/poo/out/production/poo/aula02/CelciusToFahrenheit.class differ diff --git a/1ano/2semestre/poo/out/production/poo/aula02/Countdown.class b/1ano/2semestre/poo/out/production/poo/aula02/Countdown.class index 7f1b31f..1233309 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/Countdown.class and b/1ano/2semestre/poo/out/production/poo/aula02/Countdown.class differ diff --git a/1ano/2semestre/poo/out/production/poo/aula02/DistanceBetweenPoints.class b/1ano/2semestre/poo/out/production/poo/aula02/DistanceBetweenPoints.class index 234bebc..122f743 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/DistanceBetweenPoints.class and b/1ano/2semestre/poo/out/production/poo/aula02/DistanceBetweenPoints.class differ diff --git a/1ano/2semestre/poo/out/production/poo/aula02/EnergyToHeatWater.class b/1ano/2semestre/poo/out/production/poo/aula02/EnergyToHeatWater.class index 469b999..858177d 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/EnergyToHeatWater.class and b/1ano/2semestre/poo/out/production/poo/aula02/EnergyToHeatWater.class differ diff --git a/1ano/2semestre/poo/out/production/poo/aula02/Investment.class b/1ano/2semestre/poo/out/production/poo/aula02/Investment.class index ac34fb2..1826b61 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/Investment.class and b/1ano/2semestre/poo/out/production/poo/aula02/Investment.class differ diff --git a/1ano/2semestre/poo/out/production/poo/aula02/KmToMiles.class b/1ano/2semestre/poo/out/production/poo/aula02/KmToMiles.class index 0bdc5de..0d2e8cc 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/KmToMiles.class and b/1ano/2semestre/poo/out/production/poo/aula02/KmToMiles.class differ diff --git a/1ano/2semestre/poo/out/production/poo/aula02/PythagoreanTheorem.class b/1ano/2semestre/poo/out/production/poo/aula02/PythagoreanTheorem.class index 619c224..bf8e1f6 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/PythagoreanTheorem.class and b/1ano/2semestre/poo/out/production/poo/aula02/PythagoreanTheorem.class differ 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 6460fb1..e2a5591 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/RealNumbers.class and b/1ano/2semestre/poo/out/production/poo/aula02/RealNumbers.class differ diff --git a/1ano/2semestre/poo/out/production/poo/utils/UserInput.class b/1ano/2semestre/poo/out/production/poo/utils/UserInput.class index 4ea1b41..9748a8d 100644 Binary files a/1ano/2semestre/poo/out/production/poo/utils/UserInput.class and b/1ano/2semestre/poo/out/production/poo/utils/UserInput.class differ 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