From e2511373b06e3398bbe30a71e7514e776d236e00 Mon Sep 17 00:00:00 2001 From: lenadekart Date: Fri, 14 Mar 2025 17:25:23 +0500 Subject: [PATCH 1/6] =?UTF-8?q?=D0=A1=D0=B8=D0=BC=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BA=D0=BE=20=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=201.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task01/src/com/example/task01/Point.java | 21 +++++++++++++++++++ task01/src/com/example/task01/Task01Main.java | 8 ++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/task01/src/com/example/task01/Point.java b/task01/src/com/example/task01/Point.java index ec5c69e8..26f5d86e 100644 --- a/task01/src/com/example/task01/Point.java +++ b/task01/src/com/example/task01/Point.java @@ -7,6 +7,27 @@ public class Point { int x; int y; + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + void flip() { + int temp = this.x; + this.x = this.y*(-1); + this.y = temp*(-1); + } + + double distance(Point point) { + int a = this.x - point.x; + int b = this.y - point.y; + return Math.sqrt(a*a + b*b); + } + + public String toString() { + return "(" + this.x + ", " + this.y + ")"; + } + void print() { String pointToString = String.format("(%d, %d)", x, y); System.out.println(pointToString); diff --git a/task01/src/com/example/task01/Task01Main.java b/task01/src/com/example/task01/Task01Main.java index 7d71173a..9767f237 100644 --- a/task01/src/com/example/task01/Task01Main.java +++ b/task01/src/com/example/task01/Task01Main.java @@ -2,12 +2,8 @@ public class Task01Main { public static void main(String[] args) { - Point p1 = new Point(); - p1.x = 10; - p1.y = 45; - Point p2 = new Point(); - p2.x = 78; - p2.y = 12; + Point p1 = new Point(10, 45); + Point p2 = new Point(78, 12); System.out.println("Point 1:"); p1.print(); From dad0aa99a5370a5d97e4254829f74813584b17f5 Mon Sep 17 00:00:00 2001 From: lenadekart Date: Fri, 14 Mar 2025 17:30:43 +0500 Subject: [PATCH 2/6] =?UTF-8?q?=D0=A1=D0=B8=D0=BC=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BA=D0=BE=20=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=201.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task01/src/com/example/task01/Point.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/task01/src/com/example/task01/Point.java b/task01/src/com/example/task01/Point.java index 26f5d86e..df141641 100644 --- a/task01/src/com/example/task01/Point.java +++ b/task01/src/com/example/task01/Point.java @@ -13,19 +13,19 @@ public Point(int x, int y) { } void flip() { - int temp = this.x; - this.x = this.y*(-1); - this.y = temp*(-1); + int temp = x; + x = y*(-1); + y = temp*(-1); } double distance(Point point) { - int a = this.x - point.x; - int b = this.y - point.y; + int a = x - point.x; + int b = y - point.y; return Math.sqrt(a*a + b*b); } public String toString() { - return "(" + this.x + ", " + this.y + ")"; + return "(" + x + ", " + y + ")"; } void print() { From dc3ca502d5cbc47018dfe47e59ef99ca3eeea5b8 Mon Sep 17 00:00:00 2001 From: lenadekart Date: Fri, 14 Mar 2025 17:54:26 +0500 Subject: [PATCH 3/6] =?UTF-8?q?=D0=A1=D0=B8=D0=BC=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BA=D0=BE=20=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=202.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task02/src/com/example/task02/Task02Main.java | 3 +- task02/src/com/example/task02/TimeSpan.java | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 task02/src/com/example/task02/TimeSpan.java diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index 644a0eba..cd24b42a 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -2,6 +2,7 @@ public class Task02Main { public static void main(String[] args) { - + System.out.println(Math.floorDiv(25, 60)); + System.out.println(Math.floorMod(25, 60)); } } diff --git a/task02/src/com/example/task02/TimeSpan.java b/task02/src/com/example/task02/TimeSpan.java new file mode 100644 index 00000000..6ad30398 --- /dev/null +++ b/task02/src/com/example/task02/TimeSpan.java @@ -0,0 +1,69 @@ +package com.example.task02; + +public class TimeSpan { + private int hour; + private int minute; + private int second; + + public TimeSpan(int hour, int minute, int second) { + this.hour = hour; + this.minute = minute; + this.second = second; + correct(); + } + + public void correct() { + minute += Math.floorDiv(second, 60); + second = Math.floorMod(second, 60); + + hour += Math.floorDiv(minute, 60); + minute = Math.floorMod(minute, 60); + } + + + public int getHour() { + return hour; + } + + public void setHour(int hour) { + this.hour = hour; + correct(); + } + + public int getMinute() { + return minute; + } + + public void setMinute(int minute) { + this.minute = minute; + correct(); + } + + public int getSecond() { + return second; + } + + public void setSecond(int second) { + this.second = second; + correct(); + } + + void add(TimeSpan time) { + hour += time.hour; + minute += time.minute; + second += time.second; + correct(); + } + + void subtract(TimeSpan time) { + hour -= time.hour; + minute -= time.minute; + second -= time.second; + correct(); + } + + public String toString() { + return hour + ":" + minute + ":" + second; + } +} + From 5be51066e707ed6dacb63e6bc3460569034351b1 Mon Sep 17 00:00:00 2001 From: lenadekart Date: Fri, 14 Mar 2025 18:43:34 +0500 Subject: [PATCH 4/6] =?UTF-8?q?=D0=A1=D0=B8=D0=BC=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BA=D0=BE=20=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=203.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/example/task03/ComplexNumber.java | 25 +++++++++++++++++++ task03/src/com/example/task03/Task03Main.java | 9 ++++++- 2 files changed, 33 insertions(+), 1 deletion(-) 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..ed3a0262 --- /dev/null +++ b/task03/src/com/example/task03/ComplexNumber.java @@ -0,0 +1,25 @@ +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 addend) { + return new ComplexNumber(real + addend.real, imaginary + addend.imaginary); + } + + public ComplexNumber multiply(ComplexNumber multiplicand) { + double real = this.real * multiplicand.real - this.imaginary * multiplicand.imaginary; + double imaginary = this.imaginary * multiplicand.imaginary + this.real * multiplicand.real; + return new ComplexNumber(real, imaginary); + } + + public String toString() { + return String.format("%.2f + %.2fi", real, imaginary); + } +} \ 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..f14ec082 100644 --- a/task03/src/com/example/task03/Task03Main.java +++ b/task03/src/com/example/task03/Task03Main.java @@ -2,6 +2,13 @@ public class Task03Main { public static void main(String[] args) { + ComplexNumber c1 = new ComplexNumber(3, 4); + ComplexNumber c2 = new ComplexNumber(1, -2); + ComplexNumber sum = c1.add(c2); + ComplexNumber product = c1.multiply(c2); + + System.out.println("Сумма: " + sum); + System.out.println("Произведение: " + product); } -} +} \ No newline at end of file From af0ba6df1b3306e073f53d992ff4ce52aef97460 Mon Sep 17 00:00:00 2001 From: lenadekart Date: Fri, 14 Mar 2025 19:45:30 +0500 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A1=D0=B8=D0=BC=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BA=D0=BE=20=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=204.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task04/src/com/example/task04/Line.java | 33 +++++++++++++++++++ task04/src/com/example/task04/Point.java | 29 ++++++++++++++++ task04/src/com/example/task04/Task04Main.java | 10 +++++- 3 files changed, 71 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..fa235c50 --- /dev/null +++ b/task04/src/com/example/task04/Line.java @@ -0,0 +1,33 @@ +package com.example.task04; + +public class Line { + private Point p1; + private 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 String toString() { + return "Line [p1=" + p1 + ", p2=" + p2 + "]"; + } + + public boolean isCollinearLine(Point p) { + double area = 0.5 * Math.abs( + p1.x * (p2.y - p.y) + + p2.x * (p.y - p1.y) + + p.x * (p1.y - p2.y) + ); + + return area == 0; + } +} diff --git a/task04/src/com/example/task04/Point.java b/task04/src/com/example/task04/Point.java new file mode 100644 index 00000000..3d38dbe7 --- /dev/null +++ b/task04/src/com/example/task04/Point.java @@ -0,0 +1,29 @@ +package com.example.task04; + +/** + * Класс точки на плоскости + */ +public class Point { + final int x; + final int y; + + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + double distance(Point point) { + int a = x - point.x; + int b = y - point.y; + return Math.sqrt(a*a + b*b); + } + + public String toString() { + return "(" + x + ", " + y + ")"; + } + + void print() { + String pointToString = String.format("(%d, %d)", x, y); + System.out.println(pointToString); + } +} diff --git a/task04/src/com/example/task04/Task04Main.java b/task04/src/com/example/task04/Task04Main.java index 55917a30..895dcbae 100644 --- a/task04/src/com/example/task04/Task04Main.java +++ b/task04/src/com/example/task04/Task04Main.java @@ -2,6 +2,14 @@ public class Task04Main { public static void main(String[] args) { - + Line line1 = new Line(new Point(0,0), new Point(5,5)); + Point[] points = new Point[7]; + for (int i = 0; i < 6; i++) { + points[i] = new Point(i,i); + } + points[6] = new Point(1,2); + for (Point point: points) { + System.out.println(line1+" | isCollinearLine("+point+"): "+line1.isCollinearLine(point)); + } } } From bdeb78d14d7a7eb0fb945f5b3ceaf9594e569c35 Mon Sep 17 00:00:00 2001 From: lenadekart Date: Fri, 14 Mar 2025 19:53:08 +0500 Subject: [PATCH 6/6] =?UTF-8?q?=D0=A1=D0=B8=D0=BC=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BA=D0=BE=20=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=205.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task05/src/com/example/task05/Point.java | 15 +++--- .../src/com/example/task05/PolygonalLine.java | 54 +++++++++++++++++-- .../com/example/task05/PolygonalLinePart.java | 28 ++++++++++ 3 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 task05/src/com/example/task05/PolygonalLinePart.java diff --git a/task05/src/com/example/task05/Point.java b/task05/src/com/example/task05/Point.java index 968ea652..614af766 100644 --- a/task05/src/com/example/task05/Point.java +++ b/task05/src/com/example/task05/Point.java @@ -11,8 +11,12 @@ 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 +25,7 @@ public Point(double x, double y) { * @return координату точки по оси X */ public double getX() { - // TODO: реализовать - throw new AssertionError(); + return x; } /** @@ -31,8 +34,7 @@ public double getX() { * @return координату точки по оси Y */ public double getY() { - // TODO: реализовать - throw new AssertionError(); + return y; } /** @@ -42,8 +44,7 @@ public double getY() { * @return расстояние от текущей точки до переданной */ public double getLength(Point point) { - // TODO: реализовать - throw new AssertionError(); + return Math.pow(Math.pow(point.x - x, 2) + Math.pow(point.y -y, 2), 0.5); } } diff --git a/task05/src/com/example/task05/PolygonalLine.java b/task05/src/com/example/task05/PolygonalLine.java index b534bfd5..5238f03a 100644 --- a/task05/src/com/example/task05/PolygonalLine.java +++ b/task05/src/com/example/task05/PolygonalLine.java @@ -10,8 +10,26 @@ public class PolygonalLine { * * @param points массив точек, которыми нужно проинициализировать ломаную линию */ + PolygonalLinePart firstLinePart; + PolygonalLinePart lastLinePart; + private Point tempPoint; + public void setPoints(Point[] points) { - // TODO: реализовать + for (int i = 0; i < points.length; i++){ + if (i == points.length - 1) + continue; + Point firstPoint = new Point(points[i].getX(), points[i].getY()); + Point secondPoint = new Point(points[i+1].getX(), points[i+1].getY()); + + PolygonalLinePart iterationLinePart = new PolygonalLinePart(firstPoint, secondPoint); + if (firstLinePart == null){ + firstLinePart = iterationLinePart; + lastLinePart = iterationLinePart; + continue; + } + lastLinePart.linkToNextLine(iterationLinePart); + lastLinePart = iterationLinePart; + } } /** @@ -20,7 +38,27 @@ public void setPoints(Point[] points) { * @param point точка, которую нужно добавить к ломаной */ public void addPoint(Point point) { - // TODO: реализовать + point = new Point(point.getX(), point.getY()); + + Point firstPoint; + if (lastLinePart != null) + firstPoint = lastLinePart.getP2(); + else if (tempPoint == null) { + tempPoint = point; + return; + } else { + firstPoint = tempPoint; + } + + PolygonalLinePart newLinePart = new PolygonalLinePart(firstPoint, point); + if (firstLinePart == null) { + firstLinePart = newLinePart; + lastLinePart = newLinePart; + } + else { + lastLinePart.linkToNextLine(newLinePart); + lastLinePart = newLinePart; + } } /** @@ -30,7 +68,8 @@ public void addPoint(Point point) { * @param y координата по оси ординат */ public void addPoint(double x, double y) { - // TODO: реализовать + Point point = new Point(x, y); + addPoint(point); } /** @@ -39,8 +78,13 @@ public void addPoint(double x, double y) { * @return длину ломаной линии */ public double getLength() { - // TODO: реализовать - throw new AssertionError(); + double result = 0; + PolygonalLinePart tempLine = firstLinePart; + while (tempLine != null) { + result += tempLine.getP1().getLength(tempLine.getP2()); + tempLine = tempLine.nextLinePart; + } + return result; } } diff --git a/task05/src/com/example/task05/PolygonalLinePart.java b/task05/src/com/example/task05/PolygonalLinePart.java new file mode 100644 index 00000000..8967cc34 --- /dev/null +++ b/task05/src/com/example/task05/PolygonalLinePart.java @@ -0,0 +1,28 @@ + +package com.example.task05; + +public class PolygonalLinePart { + private Point p1; + private Point p2; + public PolygonalLinePart nextLinePart; + public PolygonalLinePart previousLinePart; + public PolygonalLinePart(Point p1, Point p2){ + this.p1 = p1; + this.p2 = p2; + } + + public void linkToNextLine(PolygonalLinePart polygonalLinePart){ + nextLinePart = polygonalLinePart; + polygonalLinePart.previousLinePart = this; + } + + public Point getP1(){ + return p1; + } + public Point getP2(){ + return p2; + } + public String toString(){ + return "["+p1.toString()+";"+p2.toString()+"]"; + } +} \ No newline at end of file