[POO] Created the menu for Shapes.java

This commit is contained in:
TiagoRG 2023-03-08 21:01:36 +00:00
parent c898fde23b
commit 9c7e38b027
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
1 changed files with 68 additions and 65 deletions

View File

@ -130,26 +130,34 @@ 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.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: "); System.out.print("\n\n\nLado 1 do triangulo 1: ");
double side1 = UserInput.getPositiveNumber(sin); double side1 = UserInput.getPositiveNumber(sin);
System.out.print("Lado 2 do triangulo 1: "); System.out.print("Lado 2 do triangulo 1: ");
@ -164,36 +172,31 @@ public class Shapes {
System.out.print("Lado 3 do triangulo 2: "); System.out.print("Lado 3 do triangulo 2: ");
side3 = UserInput.getPositiveNumber(sin); side3 = UserInput.getPositiveNumber(sin);
Triangle t2 = new Triangle(side1, side2, side3); Triangle t2 = new Triangle(side1, side2, side3);
System.out.println("Triangulo 1: " + t1); System.out.println("Triangulo 1: " + t1);
System.out.println("Area do triangulo 1: " + t1.getArea()); System.out.println("Area do triangulo 1: " + t1.getArea());
System.out.println("Perimetro do triangulo 1: " + t1.getPerimeter()); System.out.println("Perimetro do triangulo 1: " + t1.getPerimeter());
System.out.println("Triangulo 2: " + t2); System.out.println("Triangulo 2: " + t2);
System.out.println("Area do triangulo 2: " + t2.getArea()); System.out.println("Area do triangulo 2: " + t2.getArea());
System.out.println("Perimetro do triangulo 2: " + t2.getPerimeter()); System.out.println("Perimetro do triangulo 2: " + t2.getPerimeter());
System.out.println("Triangulo 1 e igual ao triangulo 2? " + t1.equals(t2)); System.out.println("Triangulo 1 e igual ao triangulo 2? " + t1.equals(t2) + "\n\n");
}
case 3 -> {
// Rectangle System.out.print("Raio do circulo 1: ");
System.out.print("\n\n\nLado 1 do retangulo 1: "); double radius = UserInput.getPositiveNumber(sin);
side1 = UserInput.getPositiveNumber(sin); Circle c1 = new Circle(radius);
System.out.print("Lado 2 do retangulo 1: "); System.out.print("Raio do circulo 2: ");
side2 = UserInput.getPositiveNumber(sin); radius = UserInput.getPositiveNumber(sin);
Rectangle r1 = new Rectangle(side1, side2); Circle c2 = new Circle(radius);
System.out.print("Lado 1 do retangulo 2: "); System.out.println("Circulo 1: " + c1);
side1 = UserInput.getPositiveNumber(sin); System.out.println("Area do circulo 1: " + c1.getArea());
System.out.print("Lado 2 do retangulo 2: "); System.out.println("Perimetro do circulo 1: " + c1.getPerimeter());
side2 = UserInput.getPositiveNumber(sin); System.out.println("Circulo 2: " + c2);
Rectangle r2 = new Rectangle(side1, side2); System.out.println("Area do circulo 2: " + c2.getArea());
System.out.println("Perimetro do circulo 2: " + c2.getPerimeter());
System.out.println("Retangulo 1: " + r1); System.out.println("Circulo 1 e igual ao circulo 2? " + c1.equals(c2) + "\n\n");
System.out.println("Area do retangulo 1: " + r1.getArea()); }
System.out.println("Perimetro do retangulo 1: " + r1.getPerimeter()); default -> System.out.println("Opção inválida.");
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();
} }
} }