Initial commit

This commit is contained in:
2025-11-06 10:29:13 +08:00
commit 0becd14830
318 changed files with 7145 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package Exp3.Task1;
import static java.lang.Math.abs;
public class Rectangle {
private double lx, ly, rx, ry;
public Rectangle(double rx, double ry) {
this.lx = 0;
this.ly = 0;
this.rx = rx;
this.ry = ry;
}
public Rectangle(double lx, double ly, double rx, double ry) {
this.lx = lx;
this.ly = ly;
this.rx = rx;
this.ry = ry;
}
public double getAttribute(String attribute) {
return switch (attribute) {
case "lx" -> lx;
case "ly" -> ly;
case "rx" -> rx;
case "ry" -> ry;
default -> 0;
};
}
public void setAttribute(String attribute, double value) {
switch (attribute) {
case "lx": lx = value; break;
case "ly": ly = value; break;
case "rx": rx = value; break;
case "ry": ry = value; break;
default: System.out.println("Invalid attribute"); break;
}
}
public double getC() {
return 2 * (abs(rx - lx) + abs(ry - ly));
}
public double getArea() {
return abs((rx - lx) * (ry - ly));
}
}