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 f52193537a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 65 deletions

Binary file not shown.

Binary file not shown.

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.");
}
}
}
}