Merge pull request #39 from TiagoRG/dev-tiagorg

[POO] Created the menu for Shapes.java
[LABI] tema03 material added
This commit is contained in:
Tiago Garcia 2023-03-08 21:10:19 +00:00 committed by GitHub
commit a4b6800f0b
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
3 changed files with 68 additions and 65 deletions

Binary file not shown.

Binary file not shown.

View File

@ -130,70 +130,73 @@ public class Shapes {
public static void main(String[] args) { public static void main(String[] args) {
Scanner sin = new Scanner(System.in); Scanner sin = new Scanner(System.in);
// Circle while (true) {
System.out.println("Escolha uma forma:\n0 - Sair\n1 - Retangulo\n2 - Triangulo\n3 - Circulo");
System.out.print("Raio do circulo 1: "); int choice = sin.nextInt();
double radius = UserInput.getPositiveNumber(sin); switch (choice) {
Circle c1 = new Circle(radius); case 0 -> {
System.out.print("Raio do circulo 2: "); sin.close();
radius = UserInput.getPositiveNumber(sin); System.exit(0);
Circle c2 = new Circle(radius); }
case 1 -> {
System.out.println("Circulo 1: " + c1); System.out.print("\n\nLado 1 do retangulo 1: ");
System.out.println("Area do circulo 1: " + c1.getArea()); double side1 = UserInput.getPositiveNumber(sin);
System.out.println("Perimetro do circulo 1: " + c1.getPerimeter()); System.out.print("Lado 2 do retangulo 1: ");
System.out.println("Circulo 2: " + c2); double side2 = UserInput.getPositiveNumber(sin);
System.out.println("Area do circulo 2: " + c2.getArea()); Rectangle r1 = new Rectangle(side1, side2);
System.out.println("Perimetro do circulo 2: " + c2.getPerimeter()); System.out.print("Lado 1 do retangulo 2: ");
System.out.println("Circulo 1 e igual ao circulo 2? " + c1.equals(c2)); side1 = UserInput.getPositiveNumber(sin);
System.out.print("Lado 2 do retangulo 2: ");
side2 = UserInput.getPositiveNumber(sin);
// Triangle Rectangle r2 = new Rectangle(side1, side2);
System.out.println("Retangulo 1: " + r1);
System.out.print("\n\n\nLado 1 do triangulo 1: "); System.out.println("Area do retangulo 1: " + r1.getArea());
double side1 = UserInput.getPositiveNumber(sin); System.out.println("Perimetro do retangulo 1: " + r1.getPerimeter());
System.out.print("Lado 2 do triangulo 1: "); System.out.println("Retangulo 2: " + r2);
double side2 = UserInput.getPositiveNumber(sin); System.out.println("Area do retangulo 2: " + r2.getArea());
System.out.print("Lado 3 do triangulo 1: "); System.out.println("Perimetro do retangulo 2: " + r2.getPerimeter());
double side3 = UserInput.getPositiveNumber(sin); System.out.println("Retangulo 1 e igual ao retangulo 2? " + r1.equals(r2) + "\n\n");
Triangle t1 = new Triangle(side1, side2, side3); }
System.out.print("Lado 1 do triangulo 2: "); case 2 -> {
side1 = UserInput.getPositiveNumber(sin); System.out.print("\n\n\nLado 1 do triangulo 1: ");
System.out.print("Lado 2 do triangulo 2: "); double side1 = UserInput.getPositiveNumber(sin);
side2 = UserInput.getPositiveNumber(sin); System.out.print("Lado 2 do triangulo 1: ");
System.out.print("Lado 3 do triangulo 2: "); double side2 = UserInput.getPositiveNumber(sin);
side3 = UserInput.getPositiveNumber(sin); System.out.print("Lado 3 do triangulo 1: ");
Triangle t2 = new Triangle(side1, side2, side3); double side3 = UserInput.getPositiveNumber(sin);
Triangle t1 = new Triangle(side1, side2, side3);
System.out.println("Triangulo 1: " + t1); System.out.print("Lado 1 do triangulo 2: ");
System.out.println("Area do triangulo 1: " + t1.getArea()); side1 = UserInput.getPositiveNumber(sin);
System.out.println("Perimetro do triangulo 1: " + t1.getPerimeter()); System.out.print("Lado 2 do triangulo 2: ");
System.out.println("Triangulo 2: " + t2); side2 = UserInput.getPositiveNumber(sin);
System.out.println("Area do triangulo 2: " + t2.getArea()); System.out.print("Lado 3 do triangulo 2: ");
System.out.println("Perimetro do triangulo 2: " + t2.getPerimeter()); side3 = UserInput.getPositiveNumber(sin);
System.out.println("Triangulo 1 e igual ao triangulo 2? " + t1.equals(t2)); Triangle t2 = new Triangle(side1, side2, side3);
System.out.println("Triangulo 1: " + t1);
System.out.println("Area do triangulo 1: " + t1.getArea());
// Rectangle System.out.println("Perimetro do triangulo 1: " + t1.getPerimeter());
System.out.print("\n\n\nLado 1 do retangulo 1: "); System.out.println("Triangulo 2: " + t2);
side1 = UserInput.getPositiveNumber(sin); System.out.println("Area do triangulo 2: " + t2.getArea());
System.out.print("Lado 2 do retangulo 1: "); System.out.println("Perimetro do triangulo 2: " + t2.getPerimeter());
side2 = UserInput.getPositiveNumber(sin); System.out.println("Triangulo 1 e igual ao triangulo 2? " + t1.equals(t2) + "\n\n");
Rectangle r1 = new Rectangle(side1, side2); }
System.out.print("Lado 1 do retangulo 2: "); case 3 -> {
side1 = UserInput.getPositiveNumber(sin); System.out.print("Raio do circulo 1: ");
System.out.print("Lado 2 do retangulo 2: "); double radius = UserInput.getPositiveNumber(sin);
side2 = UserInput.getPositiveNumber(sin); Circle c1 = new Circle(radius);
Rectangle r2 = new Rectangle(side1, side2); System.out.print("Raio do circulo 2: ");
radius = UserInput.getPositiveNumber(sin);
System.out.println("Retangulo 1: " + r1); Circle c2 = new Circle(radius);
System.out.println("Area do retangulo 1: " + r1.getArea()); System.out.println("Circulo 1: " + c1);
System.out.println("Perimetro do retangulo 1: " + r1.getPerimeter()); System.out.println("Area do circulo 1: " + c1.getArea());
System.out.println("Retangulo 2: " + r2); System.out.println("Perimetro do circulo 1: " + c1.getPerimeter());
System.out.println("Area do retangulo 2: " + r2.getArea()); System.out.println("Circulo 2: " + c2);
System.out.println("Perimetro do retangulo 2: " + r2.getPerimeter()); System.out.println("Area do circulo 2: " + c2.getArea());
System.out.println("Retangulo 1 e igual ao retangulo 2? " + r1.equals(r2)); System.out.println("Perimetro do circulo 2: " + c2.getPerimeter());
System.out.println("Circulo 1 e igual ao circulo 2? " + c1.equals(c2) + "\n\n");
sin.close(); }
default -> System.out.println("Opção inválida.");
}
}
} }
} }