[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) {
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
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: ");
@ -164,36 +172,31 @@ public class Shapes {
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();
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.");
}
}
}
}