Skip to content

Instantly share code, notes, and snippets.

@claudioacioli
Created May 16, 2021 09:50
Show Gist options
  • Save claudioacioli/efc0ccafbfd9d89ec10d760e94de1ecf to your computer and use it in GitHub Desktop.
Save claudioacioli/efc0ccafbfd9d89ec10d760e94de1ecf to your computer and use it in GitHub Desktop.
Uma classe que simula um programa estruturado para calcular areas geometricas
import java.util.Scanner;
public class Areas {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double a = scan.nextDouble();
double b = scan.nextDouble();
double c = scan.nextDouble();
scan.nextLine();
scan.close();
print("TRIANGULO", triangulo(a, c));
print("CIRCULO", circulo(c));
print("TRAPEZIO", trapezio(a, b, c));
print("QUADRADO", quadrado(b));
print("RETANGULO", retangulo(a, b));
}
public static void print (String title, double value) {
System.out.printf("%s: %.3f%n", title, value);
}
public static double triangulo (double b, double h) {
return b*h/2;
}
public static double circulo (double r) {
double pi = 3.14159;
return pi * Math.pow(r, 2.0);
}
public static double trapezio (double b, double B, double h) {
return (b + B) * h/2;
}
public static double quadrado (double b) {
return Math.pow(b, 2.0);
}
public static double retangulo (double b, double h) {
return b * h;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment