From 7c7643a774ba9e31dc70b38d5ec93986fbed1108 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Wed, 8 Mar 2023 21:01:36 +0000 Subject: [PATCH] [POO] Created the menu for Shapes.java --- 1ano/2semestre/poo/src/aula04/Shapes.java | 133 +++++++++++----------- 1 file changed, 68 insertions(+), 65 deletions(-) diff --git a/1ano/2semestre/poo/src/aula04/Shapes.java b/1ano/2semestre/poo/src/aula04/Shapes.java index 24aa6f2..0e739b3 100644 --- a/1ano/2semestre/poo/src/aula04/Shapes.java +++ b/1ano/2semestre/poo/src/aula04/Shapes.java @@ -130,70 +130,73 @@ public class Shapes { public static void main(String[] args) { Scanner sin = new Scanner(System.in); - // Circle - - System.out.print("Raio do circulo 1: "); - double radius = UserInput.getPositiveNumber(sin); - Circle c1 = new Circle(radius); - System.out.print("Raio do circulo 2: "); - radius = UserInput.getPositiveNumber(sin); - Circle c2 = new Circle(radius); - - System.out.println("Circulo 1: " + c1); - System.out.println("Area do circulo 1: " + c1.getArea()); - System.out.println("Perimetro do circulo 1: " + c1.getPerimeter()); - System.out.println("Circulo 2: " + c2); - System.out.println("Area do circulo 2: " + c2.getArea()); - System.out.println("Perimetro do circulo 2: " + c2.getPerimeter()); - System.out.println("Circulo 1 e igual ao circulo 2? " + c1.equals(c2)); - - - // Triangle - - System.out.print("\n\n\nLado 1 do triangulo 1: "); - double side1 = UserInput.getPositiveNumber(sin); - System.out.print("Lado 2 do triangulo 1: "); - double side2 = UserInput.getPositiveNumber(sin); - System.out.print("Lado 3 do triangulo 1: "); - double side3 = UserInput.getPositiveNumber(sin); - Triangle t1 = new Triangle(side1, side2, side3); - System.out.print("Lado 1 do triangulo 2: "); - side1 = UserInput.getPositiveNumber(sin); - System.out.print("Lado 2 do triangulo 2: "); - side2 = UserInput.getPositiveNumber(sin); - System.out.print("Lado 3 do triangulo 2: "); - side3 = UserInput.getPositiveNumber(sin); - Triangle t2 = new Triangle(side1, side2, side3); - - System.out.println("Triangulo 1: " + t1); - System.out.println("Area do triangulo 1: " + t1.getArea()); - System.out.println("Perimetro do triangulo 1: " + t1.getPerimeter()); - System.out.println("Triangulo 2: " + t2); - System.out.println("Area do triangulo 2: " + t2.getArea()); - System.out.println("Perimetro do triangulo 2: " + t2.getPerimeter()); - System.out.println("Triangulo 1 e igual ao triangulo 2? " + t1.equals(t2)); - - - // Rectangle - System.out.print("\n\n\nLado 1 do retangulo 1: "); - side1 = UserInput.getPositiveNumber(sin); - System.out.print("Lado 2 do retangulo 1: "); - side2 = UserInput.getPositiveNumber(sin); - Rectangle r1 = new Rectangle(side1, side2); - System.out.print("Lado 1 do retangulo 2: "); - side1 = UserInput.getPositiveNumber(sin); - System.out.print("Lado 2 do retangulo 2: "); - side2 = UserInput.getPositiveNumber(sin); - Rectangle r2 = new Rectangle(side1, side2); - - System.out.println("Retangulo 1: " + r1); - System.out.println("Area do retangulo 1: " + r1.getArea()); - System.out.println("Perimetro do retangulo 1: " + r1.getPerimeter()); - System.out.println("Retangulo 2: " + r2); - System.out.println("Area do retangulo 2: " + r2.getArea()); - System.out.println("Perimetro do retangulo 2: " + r2.getPerimeter()); - System.out.println("Retangulo 1 e igual ao retangulo 2? " + r1.equals(r2)); - - sin.close(); + while (true) { + System.out.println("Escolha uma forma:\n0 - Sair\n1 - Retangulo\n2 - Triangulo\n3 - Circulo"); + int choice = sin.nextInt(); + switch (choice) { + case 0 -> { + sin.close(); + System.exit(0); + } + case 1 -> { + System.out.print("\n\nLado 1 do retangulo 1: "); + double side1 = UserInput.getPositiveNumber(sin); + System.out.print("Lado 2 do retangulo 1: "); + double side2 = UserInput.getPositiveNumber(sin); + Rectangle r1 = new Rectangle(side1, side2); + System.out.print("Lado 1 do retangulo 2: "); + side1 = UserInput.getPositiveNumber(sin); + System.out.print("Lado 2 do retangulo 2: "); + side2 = UserInput.getPositiveNumber(sin); + Rectangle r2 = new Rectangle(side1, side2); + System.out.println("Retangulo 1: " + r1); + System.out.println("Area do retangulo 1: " + r1.getArea()); + System.out.println("Perimetro do retangulo 1: " + r1.getPerimeter()); + System.out.println("Retangulo 2: " + r2); + System.out.println("Area do retangulo 2: " + r2.getArea()); + System.out.println("Perimetro do retangulo 2: " + r2.getPerimeter()); + System.out.println("Retangulo 1 e igual ao retangulo 2? " + r1.equals(r2) + "\n\n"); + } + case 2 -> { + System.out.print("\n\n\nLado 1 do triangulo 1: "); + double side1 = UserInput.getPositiveNumber(sin); + System.out.print("Lado 2 do triangulo 1: "); + double side2 = UserInput.getPositiveNumber(sin); + System.out.print("Lado 3 do triangulo 1: "); + double side3 = UserInput.getPositiveNumber(sin); + Triangle t1 = new Triangle(side1, side2, side3); + System.out.print("Lado 1 do triangulo 2: "); + side1 = UserInput.getPositiveNumber(sin); + System.out.print("Lado 2 do triangulo 2: "); + side2 = UserInput.getPositiveNumber(sin); + System.out.print("Lado 3 do triangulo 2: "); + side3 = UserInput.getPositiveNumber(sin); + Triangle t2 = new Triangle(side1, side2, side3); + System.out.println("Triangulo 1: " + t1); + System.out.println("Area do triangulo 1: " + t1.getArea()); + System.out.println("Perimetro do triangulo 1: " + t1.getPerimeter()); + System.out.println("Triangulo 2: " + t2); + System.out.println("Area do triangulo 2: " + t2.getArea()); + System.out.println("Perimetro do triangulo 2: " + t2.getPerimeter()); + System.out.println("Triangulo 1 e igual ao triangulo 2? " + t1.equals(t2) + "\n\n"); + } + case 3 -> { + System.out.print("Raio do circulo 1: "); + double radius = UserInput.getPositiveNumber(sin); + Circle c1 = new Circle(radius); + System.out.print("Raio do circulo 2: "); + radius = UserInput.getPositiveNumber(sin); + Circle c2 = new Circle(radius); + System.out.println("Circulo 1: " + c1); + System.out.println("Area do circulo 1: " + c1.getArea()); + System.out.println("Perimetro do circulo 1: " + c1.getPerimeter()); + System.out.println("Circulo 2: " + c2); + System.out.println("Area do circulo 2: " + c2.getArea()); + System.out.println("Perimetro do circulo 2: " + c2.getPerimeter()); + System.out.println("Circulo 1 e igual ao circulo 2? " + c1.equals(c2) + "\n\n"); + } + default -> System.out.println("Opção inválida."); + } + } } }