Floats reformat

This commit is contained in:
TiagoRG 2023-02-20 10:14:11 +00:00
parent 19103f82b8
commit 73fa254c3a
21 changed files with 42 additions and 14 deletions

View File

@ -5,5 +5,14 @@
* [Guião](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/guides/POO-2021-aula02.pdf) * [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) * [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) *Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -18,6 +18,8 @@ public class AverageSpeed {
double d2 = UserInput.getPositiveNumber(sin); double d2 = UserInput.getPositiveNumber(sin);
double vm = (d1 + d2) / ((d1 / v1) + (d2 / v2)); 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();
} }
} }

View File

@ -10,6 +10,8 @@ public class CelciusToFahrenheit {
Scanner sin = new Scanner(System.in); Scanner sin = new Scanner(System.in);
double celcius = sin.nextDouble(); double celcius = sin.nextDouble();
double fahrenheit = 1.8*celcius+32; 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();
} }
} }

View File

@ -11,7 +11,11 @@ public class Countdown {
System.out.print("N? "); System.out.print("N? ");
int n = sin.nextInt(); int n = sin.nextInt();
for (int i = n; i >= 0; i--) { 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 + ","); System.out.print(i%10 == 0 ? i + "\n" : i + ",");
} }
sin.close();
} }
} }

View File

@ -1,5 +1,7 @@
package aula02; package aula02;
import utils.UserInput;
import java.util.Scanner; import java.util.Scanner;
// Solução do exercício 7 // Solução do exercício 7
@ -8,15 +10,15 @@ public class DistanceBetweenPoints {
public static void main(String[] args){ public static void main(String[] args){
Scanner sin = new Scanner(System.in); Scanner sin = new Scanner(System.in);
System.out.print("Coordenadas do ponto 1 (separadas por ','): "); String[] p1 = UserInput.input(sin, "Coordenadas do ponto 1 (separadas por ','): ").split(",");
String[] p1 = sin.next().split(","); String[] p2 = UserInput.input(sin, "Coordenadas do ponto 2 (separadas por ','): ").split(",");
System.out.print("Coordenadas do ponto 2 (separadas por ','): ");
String[] p2 = sin.next().split(",");
double distance = Math.sqrt( double distance = Math.sqrt(
Math.pow(Double.parseDouble(p1[0]) - Double.parseDouble(p2[0]), 2) + Math.pow(Double.parseDouble(p1[0]) - Double.parseDouble(p2[0]), 2) +
Math.pow(Double.parseDouble(p1[1]) - Double.parseDouble(p2[1]), 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();
} }
} }

View File

@ -16,6 +16,8 @@ public class EnergyToHeatWater {
System.out.print("Temperatura final da água (ºC)? "); System.out.print("Temperatura final da água (ºC)? ");
double finalTemperature = sin.nextDouble(); double finalTemperature = sin.nextDouble();
double energy = kgOfWater * (finalTemperature - initialTemperature) * 4184; 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();
} }
} }

View File

@ -14,6 +14,8 @@ public class Investment {
System.out.print("Taxa de juro mensal (%)? "); System.out.print("Taxa de juro mensal (%)? ");
double tax = sin.nextDouble(); double tax = sin.nextDouble();
double finalWallet = initialWallet * Math.pow(1 + tax/100, 3); 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();
} }
} }

View File

@ -12,6 +12,8 @@ public class KmToMiles {
Scanner sin = new Scanner(System.in); Scanner sin = new Scanner(System.in);
double km = UserInput.getPositiveNumber(sin); double km = UserInput.getPositiveNumber(sin);
double miles = km / 1.609; double miles = km / 1.609;
System.out.printf("%fkm = %f miles", km, miles); System.out.printf("%.3fkm = %.3f miles", km, miles);
sin.close();
} }
} }

View File

@ -17,11 +17,10 @@ public class PythagoreanTheorem {
double b = UserInput.getPositiveNumber(sin); double b = UserInput.getPositiveNumber(sin);
double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); 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; System.out.printf("O comprimento da hipotenusa é %.2f e o valor do angulo entre o cateto A e a hipotenusa é %.2f°", c, angDeg);
double angRad = Math.acos(cossin);
double angDeg = angRad * 180 / Math.PI;
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();
} }
} }

View File

@ -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); System.out.printf("Valor máximo: %f\nValor mínimo: %f\nMédia: %f\nTotal: %f", max, min, (float) sum/readNumbers, sum);
sin.close();
} }
} }

View File

@ -17,5 +17,7 @@ public class SecsToHMS {
int hours = Math.round((float) (mins / 60)); int hours = Math.round((float) (mins / 60));
mins = mins % 60; mins = mins % 60;
System.out.printf("%d segundos no formato hh:mm:ss : %d:%d:%d", totalSecs, hours, mins, secs); System.out.printf("%d segundos no formato hh:mm:ss : %d:%d:%d", totalSecs, hours, mins, secs);
sin.close();
} }
} }