Skip to content
Snippets Groups Projects
Commit 3d989ef1 authored by Juuso Rytilahti's avatar Juuso Rytilahti
Browse files

translated text

parent 030381fd
Branches main
No related tags found
No related merge requests found
...@@ -59,12 +59,12 @@ public class Exercise3 { ...@@ -59,12 +59,12 @@ public class Exercise3 {
assert (x1 >= x2); assert (x1 >= x2);
assert (y1 >= y2); assert (y1 >= y2);
// triangle: draw a square around it and calculate half of the area // triangle: draw a quadrilateral around it and calculate half of the area
// square: ala = side * other side // quadrilateral: ala = side * other side
// circle: area = pi * r^2 ja r = sqrt(dx^2 + dy^2), so area = pi * (dx^2 + dy^2) // circle: area = pi * r^2 ja r = sqrt(dx^2 + dy^2), so area = pi * (dx^2 + dy^2)
return switch ((String) ps[0]) { return switch ((String) ps[0]) {
case "triangle" -> (x1 - x2) * (y1 - y2) / 2; case "triangle" -> (x1 - x2) * (y1 - y2) / 2;
case "square" -> (x1 - x2) * (y1 - y2); case "quadrilateral" -> (x1 - x2) * (y1 - y2);
case "circle" -> Math.PI * ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); case "circle" -> Math.PI * ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
default -> throw new Exception("Unfalimiar pattern!"); default -> throw new Exception("Unfalimiar pattern!");
}; };
...@@ -87,18 +87,18 @@ public class Exercise3 { ...@@ -87,18 +87,18 @@ public class Exercise3 {
if (p2[0].equals("triangle")) if (p2[0].equals("triangle"))
p2[3] = readPoint(); p2[3] = readPoint();
// laske kuvioiden käsittämien alueiden pinta-ala // Calculate the area covered by the patterns
// kuvioiden asettumista päällekkäin ei tarvitse huomioida // No need to take into account the overlapping of patterns
{ {
double area_sum = 0; double area_sum = 0;
area_sum += area(p1); area_sum += area(p1);
area_sum += area(p2); area_sum += area(p2);
System.out.printf("Kuvioiden pinta-alan summa:\n%f\n\n", area_sum); System.out.printf("Sum of area covered by the patterns:\n%f\n\n", area_sum);
} }
// laske kuvioiden käsittämän alueen ulkorajat // calculate the outer boundaries of the area covered by the patterns
int x1 = Integer.MIN_VALUE, int x1 = Integer.MIN_VALUE,
y1 = Integer.MIN_VALUE, y1 = Integer.MIN_VALUE,
...@@ -126,7 +126,7 @@ public class Exercise3 { ...@@ -126,7 +126,7 @@ public class Exercise3 {
assert (x1 >= x2); assert (x1 >= x2);
assert (y1 >= y2); assert (y1 >= y2);
System.out.printf("Kuvioiden yhteiset rajat:\n(%d, %d) x (%d, %d)\n\n", System.out.printf("The common boundaries of the patterns:\n(%d, %d) x (%d, %d)\n\n",
x2, y2, x1, y1); x2, y2, x1, y1);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment