From b7669757925bd6277e9bc401ee98caa270d06e4e Mon Sep 17 00:00:00 2001 From: glebobobr Date: Tue, 30 Sep 2025 07:37:08 +0500 Subject: [PATCH 1/5] =?UTF-8?q?=D0=92=D0=BE=D1=80=D0=BE=D0=BD=D0=B8=D0=BD?= =?UTF-8?q?=20=D0=93=D0=BB=D0=B5=D0=B1.=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=2001?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task01/src/com/example/task01/Point.java | 32 +++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/task01/src/com/example/task01/Point.java b/task01/src/com/example/task01/Point.java index ec5c69e8..3efc950b 100644 --- a/task01/src/com/example/task01/Point.java +++ b/task01/src/com/example/task01/Point.java @@ -7,8 +7,34 @@ public class Point { int x; int y; + public Point() { + this.x = 0; + this.y = 0; + } + + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + void flip() { + int temp = x; + x = -y; + y = -temp; + } + + double distance(Point point) { + int dx = this.x - point.x; + int dy = this.y - point.y; + return Math.sqrt(dx * dx + dy * dy); + } + + @Override + public String toString() { + return String.format("(%d, %d)", x, y); + } + void print() { - String pointToString = String.format("(%d, %d)", x, y); - System.out.println(pointToString); + System.out.println(toString()); } -} +} \ No newline at end of file From 57aa641a39bd1fcf8a4fef34b7a59b9d1b165560 Mon Sep 17 00:00:00 2001 From: glebobobr Date: Tue, 30 Sep 2025 07:37:26 +0500 Subject: [PATCH 2/5] =?UTF-8?q?=D0=92=D0=BE=D1=80=D0=BE=D0=BD=D0=B8=D0=BD?= =?UTF-8?q?=20=D0=93=D0=BB=D0=B5=D0=B1.=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=2002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task02/src/com/example/task02/TimeSpan.java | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 task02/src/com/example/task02/TimeSpan.java diff --git a/task02/src/com/example/task02/TimeSpan.java b/task02/src/com/example/task02/TimeSpan.java new file mode 100644 index 00000000..7f7539de --- /dev/null +++ b/task02/src/com/example/task02/TimeSpan.java @@ -0,0 +1,69 @@ +package com.example.task02; + +public class TimeSpan { + private int hours; + private int minutes; + private int seconds; + + public TimeSpan(int hours, int minutes, int seconds) { + setTime(hours, minutes, seconds); + } + + private void setTime(int hours, int minutes, int seconds) { + long totalSeconds = hours * 3600L + minutes * 60L + seconds; + + if (totalSeconds < 0) { + totalSeconds = 0; + } + + this.hours = (int) (totalSeconds / 3600); + totalSeconds %= 3600; + this.minutes = (int) (totalSeconds / 60); + this.seconds = (int) (totalSeconds % 60); + } + + public int getHours() { + return hours; + } + + public void setHours(int hours) { + setTime(hours, this.minutes, this.seconds); + } + + public int getMinutes() { + return minutes; + } + + public void setMinutes(int minutes) { + setTime(this.hours, minutes, this.seconds); + } + + public int getSeconds() { + return seconds; + } + + public void setSeconds(int seconds) { + setTime(this.hours, this.minutes, seconds); + } + + public void add(TimeSpan time) { + setTime( + this.hours + time.hours, + this.minutes + time.minutes, + this.seconds + time.seconds + ); + } + + public void subtract(TimeSpan time) { + long thisTotal = this.hours * 3600L + this.minutes * 60L + this.seconds; + long otherTotal = time.hours * 3600L + time.minutes * 60L + time.seconds; + long resultTotal = thisTotal - otherTotal; + + setTime(0, 0, (int)resultTotal); + } + + @Override + public String toString() { + return String.format("%02d:%02d:%02d", hours, minutes, seconds); + } +} \ No newline at end of file From 0f0ac09f943965b39afd852bcb7f38158812c398 Mon Sep 17 00:00:00 2001 From: glebobobr Date: Tue, 30 Sep 2025 07:37:45 +0500 Subject: [PATCH 3/5] =?UTF-8?q?=D0=92=D0=BE=D1=80=D0=BE=D0=BD=D0=B8=D0=BD?= =?UTF-8?q?=20=D0=93=D0=BB=D0=B5=D0=B1.=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=2003?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/example/task03/ComplexNumber.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 task03/src/com/example/task03/ComplexNumber.java diff --git a/task03/src/com/example/task03/ComplexNumber.java b/task03/src/com/example/task03/ComplexNumber.java new file mode 100644 index 00000000..1a094fd1 --- /dev/null +++ b/task03/src/com/example/task03/ComplexNumber.java @@ -0,0 +1,33 @@ +package com.example.task03; + +public class ComplexNumber { + private final double real; + private final double imaginary; + + public ComplexNumber(double real, double imaginary) { + this.real = real; + this.imaginary = imaginary; + } + + public ComplexNumber add(ComplexNumber other) { + return new ComplexNumber( + this.real + other.real, + this.imaginary + other.imaginary + ); + } + + public ComplexNumber multiply(ComplexNumber other) { + double newReal = this.real * other.real - this.imaginary * other.imaginary; + double newImaginary = this.real * other.imaginary + this.imaginary * other.real; + return new ComplexNumber(newReal, newImaginary); + } + + @Override + public String toString() { + if (imaginary >= 0) { + return String.format("%.2f + %.2fi", real, imaginary); + } else { + return String.format("%.2f - %.2fi", real, Math.abs(imaginary)); + } + } +} \ No newline at end of file From 735e0032b09b62d17688918843d9c985a5b7ec10 Mon Sep 17 00:00:00 2001 From: glebobobr Date: Tue, 30 Sep 2025 07:37:58 +0500 Subject: [PATCH 4/5] =?UTF-8?q?=D0=92=D0=BE=D1=80=D0=BE=D0=BD=D0=B8=D0=BD?= =?UTF-8?q?=20=D0=93=D0=BB=D0=B5=D0=B1.=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=2004?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task04/src/com/example/task04/Line.java | 32 +++++++++++++++++++ task04/src/com/example/task04/Point.java | 24 ++++++++++++++ task04/src/com/example/task04/Task04Main.java | 11 ++++++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 task04/src/com/example/task04/Line.java create mode 100644 task04/src/com/example/task04/Point.java diff --git a/task04/src/com/example/task04/Line.java b/task04/src/com/example/task04/Line.java new file mode 100644 index 00000000..05b5ac32 --- /dev/null +++ b/task04/src/com/example/task04/Line.java @@ -0,0 +1,32 @@ +package com.example.task04; + +public class Line { + private final Point p1; + private final Point p2; + + public Line(Point p1, Point p2) { + this.p1 = p1; + this.p2 = p2; + } + + public Point getP1() { + return p1; + } + + public Point getP2() { + return p2; + } + + public boolean isCollinearLine(Point p) { + int determinant = p1.getX() * (p2.getY() - p.getY()) + + p2.getX() * (p.getY() - p1.getY()) + + p.getX() * (p1.getY() - p2.getY()); + + return determinant == 0; + } + + @Override + public String toString() { + return String.format("Line[%s, %s]", p1, p2); + } +} \ No newline at end of file diff --git a/task04/src/com/example/task04/Point.java b/task04/src/com/example/task04/Point.java new file mode 100644 index 00000000..d85ebebb --- /dev/null +++ b/task04/src/com/example/task04/Point.java @@ -0,0 +1,24 @@ +package com.example.task04; + +public class Point { + private final int x; + private final int y; + + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + @Override + public String toString() { + return String.format("(%d, %d)", x, y); + } +} \ No newline at end of file diff --git a/task04/src/com/example/task04/Task04Main.java b/task04/src/com/example/task04/Task04Main.java index 55917a30..8dd8ff40 100644 --- a/task04/src/com/example/task04/Task04Main.java +++ b/task04/src/com/example/task04/Task04Main.java @@ -2,6 +2,15 @@ public class Task04Main { public static void main(String[] args) { + Point p1 = new Point(0, 0); + Point p2 = new Point(4, 4); + Point p3 = new Point(2, 2); + Point p4 = new Point(1, 2); + Line line = new Line(p1, p2); + + System.out.println("Line: " + line); + System.out.println("Point p3 " + p3 + " is collinear: " + line.isCollinearLine(p3)); + System.out.println("Point p4 " + p4 + " is collinear: " + line.isCollinearLine(p4)); } -} +} \ No newline at end of file From 5e8e997c32a5e663faca8c89351ffc653c2224a2 Mon Sep 17 00:00:00 2001 From: glebobobr Date: Tue, 30 Sep 2025 07:38:07 +0500 Subject: [PATCH 5/5] =?UTF-8?q?=D0=92=D0=BE=D1=80=D0=BE=D0=BD=D0=B8=D0=BD?= =?UTF-8?q?=20=D0=93=D0=BB=D0=B5=D0=B1.=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=2005?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task05/src/com/example/task05/Point.java | 19 +++++++------- .../src/com/example/task05/PolygonalLine.java | 25 +++++++++++++------ task05/src/com/example/task05/Task05Main.java | 16 +++++++++++- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/task05/src/com/example/task05/Point.java b/task05/src/com/example/task05/Point.java index 968ea652..41057e50 100644 --- a/task05/src/com/example/task05/Point.java +++ b/task05/src/com/example/task05/Point.java @@ -4,6 +4,8 @@ * Точка в двумерном пространстве */ public class Point { + private final double x; + private final double y; /** * Конструктор, инициализирующий координаты точки @@ -12,7 +14,8 @@ public class Point { * @param y координата по оси ординат */ public Point(double x, double y) { - throw new AssertionError(); + this.x = x; + this.y = y; } /** @@ -21,8 +24,7 @@ public Point(double x, double y) { * @return координату точки по оси X */ public double getX() { - // TODO: реализовать - throw new AssertionError(); + return x; } /** @@ -31,8 +33,7 @@ public double getX() { * @return координату точки по оси Y */ public double getY() { - // TODO: реализовать - throw new AssertionError(); + return y; } /** @@ -42,8 +43,8 @@ public double getY() { * @return расстояние от текущей точки до переданной */ public double getLength(Point point) { - // TODO: реализовать - throw new AssertionError(); + double dx = this.x - point.x; + double dy = this.y - point.y; + return Math.sqrt(dx * dx + dy * dy); } - -} +} \ No newline at end of file diff --git a/task05/src/com/example/task05/PolygonalLine.java b/task05/src/com/example/task05/PolygonalLine.java index b534bfd5..bff3939a 100644 --- a/task05/src/com/example/task05/PolygonalLine.java +++ b/task05/src/com/example/task05/PolygonalLine.java @@ -1,9 +1,13 @@ package com.example.task05; +import java.util.ArrayList; +import java.util.List; + /** * Ломаная линия */ public class PolygonalLine { + private List points = new ArrayList<>(); /** * Устанавливает точки ломаной линии @@ -11,7 +15,11 @@ public class PolygonalLine { * @param points массив точек, которыми нужно проинициализировать ломаную линию */ public void setPoints(Point[] points) { - // TODO: реализовать + this.points = new ArrayList<>(); + for (Point point : points) { + // Создаем копию каждой точки + addPoint(point.getX(), point.getY()); + } } /** @@ -20,7 +28,8 @@ public void setPoints(Point[] points) { * @param point точка, которую нужно добавить к ломаной */ public void addPoint(Point point) { - // TODO: реализовать + // Создаем новую точку вместо использования переданной + addPoint(point.getX(), point.getY()); } /** @@ -30,7 +39,7 @@ public void addPoint(Point point) { * @param y координата по оси ординат */ public void addPoint(double x, double y) { - // TODO: реализовать + points.add(new Point(x, y)); } /** @@ -39,8 +48,10 @@ public void addPoint(double x, double y) { * @return длину ломаной линии */ public double getLength() { - // TODO: реализовать - throw new AssertionError(); + double length = 0; + for (int i = 0; i < points.size() - 1; i++) { + length += points.get(i).getLength(points.get(i + 1)); + } + return length; } - -} +} \ No newline at end of file diff --git a/task05/src/com/example/task05/Task05Main.java b/task05/src/com/example/task05/Task05Main.java index 4f745fb6..c10f3410 100644 --- a/task05/src/com/example/task05/Task05Main.java +++ b/task05/src/com/example/task05/Task05Main.java @@ -2,6 +2,20 @@ public class Task05Main { public static void main(String[] args) { + PolygonalLine line = new PolygonalLine(); + line.addPoint(new Point(1, 2)); + line.addPoint(4, 6); + line.addPoint(new Point(8, 9)); + + System.out.println("Длина ломаной: " + line.getLength()); + + Point[] points = { + new Point(0, 0), + new Point(3, 4), + new Point(6, 8) + }; + line.setPoints(points); + System.out.println("Новая длина ломаной: " + line.getLength()); } -} +} \ No newline at end of file