From 2aaff8fb4b143ce53cc92a07ab8bfc72fd0cf0ec Mon Sep 17 00:00:00 2001 From: riht7405 Date: Tue, 25 Nov 2025 02:11:45 +0500 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9D=D0=B8=D0=B7=D0=B0=D0=BC=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=90=D0=B9=D0=B4=D0=B0=D1=80=20=D0=9C=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=204,=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task01/src/com/example/task01/Point.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/task01/src/com/example/task01/Point.java b/task01/src/com/example/task01/Point.java index ec5c69e8..b861ed01 100644 --- a/task01/src/com/example/task01/Point.java +++ b/task01/src/com/example/task01/Point.java @@ -1,14 +1,26 @@ package com.example.task01; -/** - * Класс точки на плоскости - */ public class Point { int x; int y; - + Point(){} + Point(int x, int y) { + this.x = x; + this.y = y; + } + void flip() { + int temp = x; + x = (-1) * y; + y = (-1) * temp; + } + double distance(Point point) { + return Math.sqrt((y - point.y) * (y - point.y) + (x - point.x) * (x - point.x)); + } + public String toString() { + return "(" + Integer.toString(x) + ", " + Integer.toString(y) + ")"; + } void print() { String pointToString = String.format("(%d, %d)", x, y); System.out.println(pointToString); } -} +} \ No newline at end of file From dbc39cafdf5ef4f407e25f6c09c06f04de720647 Mon Sep 17 00:00:00 2001 From: riht7405 Date: Tue, 25 Nov 2025 02:15:07 +0500 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9D=D0=B8=D0=B7=D0=B0=D0=BC=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=90=D0=B9=D0=B4=D0=B0=D1=80=20=D0=9C=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=204,=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task02/src/com/example/task02/TimeSpan.java | 70 +++++++++++++++++++++ 1 file changed, 70 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..1b3163a0 --- /dev/null +++ b/task02/src/com/example/task02/TimeSpan.java @@ -0,0 +1,70 @@ +package com.example.task02; + +public class TimeSpan { + private int hours; + private int minutes; + private int seconds; + + public TimeSpan(int hours, int minutes, int seconds) { + this.hours = hours + minutes / 60 + seconds / 3600; + minutes %= 60; + seconds %= 3600; + this.minutes = minutes + seconds / 60; + seconds %= 60; + this.seconds = seconds; + } + + public void setHours(int hours) { + this.hours = hours; + } + + public void setMinutes(int minutes) { + hours += minutes / 60; + this.minutes = minutes % 60; + } + + public void setSeconds(int seconds) { + hours = seconds / 3600; + seconds %= 3600; + minutes = seconds / 60; + this.seconds = seconds % 60; + } + + public int getHours() { + return hours; + } + + public int getMinutes() { + return minutes; + } + + public int getSeconds() { + return seconds; + } + + void add(TimeSpan time) { + seconds += time.getSeconds(); + minutes += time.getMinutes() + seconds / 60; + seconds %= 60; + hours += time.getHours() + minutes / 60 + seconds / 60; + } + + void subtract(TimeSpan time) { + seconds -= time.getSeconds(); + if (seconds < 0) { + seconds += 60; + minutes--; + } + minutes -= time.getMinutes(); + if (minutes < 0) { + minutes += 60; + hours--; + } + hours -= time.getHours(); + if (hours < 0) System.err.println("Отрицательное время?"); + } + + public String toString() { + return Integer.toString(hours) + ":" + Integer.toString(minutes) + ":" +Integer.toString(seconds); + } +} \ No newline at end of file From a54dcb21ec6d06e242a351adf821ab0d482dacfe Mon Sep 17 00:00:00 2001 From: riht7405 Date: Tue, 25 Nov 2025 02:22:24 +0500 Subject: [PATCH 3/4] =?UTF-8?q?=D0=9D=D0=B8=D0=B7=D0=B0=D0=BC=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=90=D0=B9=D0=B4=D0=B0=D1=80=20=D0=9C=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=204,=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=203-4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task03/src/com/example/task03/ComplexNum.java | 39 +++++++++++++++++++ task03/src/com/example/task03/Task03Main.java | 7 +++- task04/src/com/example/task04/Line.java | 26 +++++++++++++ task04/src/com/example/task04/Point.java | 18 +++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 task03/src/com/example/task03/ComplexNum.java create mode 100644 task04/src/com/example/task04/Line.java create mode 100644 task04/src/com/example/task04/Point.java diff --git a/task03/src/com/example/task03/ComplexNum.java b/task03/src/com/example/task03/ComplexNum.java new file mode 100644 index 00000000..0c4f085c --- /dev/null +++ b/task03/src/com/example/task03/ComplexNum.java @@ -0,0 +1,39 @@ +package com.example.task03; + +public class ComplexNum { + private int real; + private int imaginary; + + ComplexNum(int real, int imaginary) { + this.real = real; + this.imaginary = imaginary; + } + + public void setReal(int real) { + this.real = real; + } + + public void setImaginary(int imaginary) { + this.imaginary = imaginary; + } + + public int getReal() { + return real; + } + + public int getImaginary() { + return imaginary; + } + + public ComplexNum add(ComplexNum number) { + return new ComplexNum(real + number.real, imaginary + number.imaginary); + } + + public ComplexNum mul(ComplexNum number) { + return new ComplexNum(real * number.real - imaginary * number.imaginary, imaginary * number.real + number.imaginary * real); + } + + public String toString() { + return "(" + Integer.toString(real) + ", " + Integer.toString(imaginary) + "i" + ")"; + } +} \ No newline at end of file diff --git a/task03/src/com/example/task03/Task03Main.java b/task03/src/com/example/task03/Task03Main.java index ae40e6f2..22abf2d8 100644 --- a/task03/src/com/example/task03/Task03Main.java +++ b/task03/src/com/example/task03/Task03Main.java @@ -2,6 +2,9 @@ public class Task03Main { public static void main(String[] args) { - + ComplexNum a = new ComplexNum(1, 2); + ComplexNum b = new ComplexNum(3, 4); + System.out.println(a + " + " + b + " = " + a.add(b)); + System.out.println(a + " * " + b + " = " + a.mul(b)); } -} +} \ No newline at end of file diff --git a/task04/src/com/example/task04/Line.java b/task04/src/com/example/task04/Line.java new file mode 100644 index 00000000..4fa86989 --- /dev/null +++ b/task04/src/com/example/task04/Line.java @@ -0,0 +1,26 @@ +package com.example.task04; + +public class Line { + private Point p1; + private Point p2; + Line(Point p1, Point p2){ + this.p1 = p1; + this.p2 = p2; + } + + public Point getP1() { + return p1; + } + + public Point getP2() { + return p2; + } + + public String toString() { + return p1.toString() + ":" + p2.toString(); + } + + public boolean isCollinearLine(Point p){ + return (p.x - p1.x)/(p2.x - p1.x) == (p.y - p1.y)/(p2.y - p1.y); + } +} \ 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..075574e5 --- /dev/null +++ b/task04/src/com/example/task04/Point.java @@ -0,0 +1,18 @@ +package com.example.task04; + +public class Point { + final int x; + final int y; + Point(int x, int y) { + this.x = x; + this.y = y; + } + + double distance(Point point) { + return Math.sqrt((y - point.y) * (y - point.y) + (x - point.x) * (x - point.x)); + } + public String toString() { + return "(" + Integer.toString(x) + ", " + Integer.toString(y) + ")"; + } + +} \ No newline at end of file From 2812198724edda4d07d900df60ac2667c4b44ad2 Mon Sep 17 00:00:00 2001 From: riht7405 Date: Tue, 25 Nov 2025 02:44:23 +0500 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9D=D0=B8=D0=B7=D0=B0=D0=BC=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=90=D0=B9=D0=B4=D0=B0=D1=80=20=D0=9C=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=204,=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 3 ++- task05/src/com/example/task05/Point.java | 16 ++++++------- .../src/com/example/task05/PolygonalLine.java | 24 +++++++++++++------ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index c76d6984..9c443e2a 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ subprojects { } dependencies { - compile group: 'junit', name: 'junit', version: '4.12' - compile group: 'org.assertj', name: 'assertj-core', version: '3.10.0' + implementation group: 'junit', name: 'junit', version: '4.12' + implementation group: 'org.assertj', name: 'assertj-core', version: '3.10.0' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 717f0389..53b19b23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Tue Nov 25 02:33:51 YEKT 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip diff --git a/task05/src/com/example/task05/Point.java b/task05/src/com/example/task05/Point.java index 968ea652..e45f9fb2 100644 --- a/task05/src/com/example/task05/Point.java +++ b/task05/src/com/example/task05/Point.java @@ -11,8 +11,11 @@ public class Point { * @param x координата по оси абсцисс * @param y координата по оси ординат */ + private final double x; + private final double 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,7 @@ public double getY() { * @return расстояние от текущей точки до переданной */ public double getLength(Point point) { - // TODO: реализовать - throw new AssertionError(); + return Math.sqrt((x - point.x) * (x - point.x) + (y - point.y) * (y - point.y)); } -} +} \ 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..92e8380a 100644 --- a/task05/src/com/example/task05/PolygonalLine.java +++ b/task05/src/com/example/task05/PolygonalLine.java @@ -1,5 +1,8 @@ package com.example.task05; +import java.util.ArrayList; +import java.util.Arrays; + /** * Ломаная линия */ @@ -10,8 +13,13 @@ public class PolygonalLine { * * @param points массив точек, которыми нужно проинициализировать ломаную линию */ + ArrayList points = new ArrayList<>(); // Инициализация ArrayList + public void setPoints(Point[] points) { - // TODO: реализовать + this.points.clear(); // Очищаем существующие точки + for (Point point : points) { + addPoint(point); // Добавляем копии точек + } } /** @@ -20,7 +28,7 @@ public void setPoints(Point[] points) { * @param point точка, которую нужно добавить к ломаной */ public void addPoint(Point point) { - // TODO: реализовать + points.add(new Point(point.getX(), point.getY())); // Создаем копию точки } /** @@ -30,7 +38,7 @@ public void addPoint(Point point) { * @param y координата по оси ординат */ public void addPoint(double x, double y) { - // TODO: реализовать + points.add(new Point(x, y)); } /** @@ -39,8 +47,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