From 084a5a6322a2f0dfbe10e05765b3dd5dea567608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9?= Date: Sun, 28 Sep 2025 16:22:13 +0500 Subject: [PATCH 1/5] =?UTF-8?q?=D0=9F=D0=BB=D0=BE=D1=82=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=9F=D1=80=D0=98-202=20=E2=80=94=20=D0=97=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task01/src/com/example/task01/Point.java | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/task01/src/com/example/task01/Point.java b/task01/src/com/example/task01/Point.java index ec5c69e8..4ae45bd8 100644 --- a/task01/src/com/example/task01/Point.java +++ b/task01/src/com/example/task01/Point.java @@ -7,8 +7,32 @@ public class Point { int x; int y; + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + public Point() { + this(0, 0); + } + + void flip() { + int temp = x; + x = -y; + y = -temp; + } + + double distance(Point point) { + int xDif = this.x - point.x; + int yDif = this.y - point.y; + return Math.sqrt(xDif * xDif + yDif * yDif); + } + + 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(this); } } From ee941c372e5a591b5578433d13634bc3d451b32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9?= Date: Sun, 28 Sep 2025 18:27:43 +0500 Subject: [PATCH 2/5] =?UTF-8?q?=D0=9F=D0=BB=D0=BE=D1=82=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=9F=D1=80=D0=98-202=20=E2=80=94=20=D0=97=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task02/src/com/example/task02/TimeSpan.java | 102 ++++++++++++++++++++ 1 file changed, 102 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..ed23578e --- /dev/null +++ b/task02/src/com/example/task02/TimeSpan.java @@ -0,0 +1,102 @@ +package com.example.task02; + +import java.sql.Time; +import java.text.MessageFormat; + +public class TimeSpan { + private int hours; + private int minutes; + private int seconds; + + public TimeSpan(int h, int m, int s) { + hours = h; + minutes = m; + seconds = s; + } + + public int getHours() { + return hours; + } + + public void setHours(int hours) { + this.hours = hours; + } + + public int getMinutes() { + return minutes; + } + + public void setMinutes(int minutes) { + int h = minutes / 60; + int m = minutes % 60; + + hours = h; + minutes = m; + } + + public int getSeconds() { + return seconds; + } + + public void setSeconds(int seconds) { + int h = seconds / 3600; + int m = seconds % 3600 / 60; + int s = seconds % 3600 % 60; + + hours = h; + minutes = m; + seconds = s; + } + + private void addAndSeparateMinutes(int m1, int m2) { + hours += (m1 + m2) / 60; + minutes += (m1 + m2) % 60; + } + + private void subAndSeparateMinutes(int m1, int m2) { + hours -= (m1 - m2) / 60; + minutes -= (m1 - m2) % 60; + } + + public void add(TimeSpan time) { + hours += time.hours; + + if (minutes + time.minutes >= 60) + addAndSeparateMinutes(minutes, time.minutes); + else + minutes += time.minutes; + + if (seconds + time.seconds >= 60) { + int tempMinutes = time.seconds / 60; + if (minutes + tempMinutes >= 60) { + addAndSeparateMinutes(minutes, tempMinutes); + } + seconds += (seconds + time.seconds) % 60; + } + else + seconds += time.seconds; + } + + public void subtract(TimeSpan time) { + hours -= time.hours; + + if (minutes - time.minutes < 0) + subAndSeparateMinutes(minutes, time.minutes); + else + minutes -= time.minutes; + + if (seconds - time.seconds < 0) { + int tempMinutes = time.seconds / 60; + if (minutes - tempMinutes < 0) { + subAndSeparateMinutes(minutes, tempMinutes); + } + seconds -= (seconds - time.seconds) % 60; + } + else + seconds -= time.seconds; + } + + public String toString() { + return MessageFormat.format("Time — {0}h:{1}m:{2}s", hours, minutes, seconds); + } +} From c757678a01bedebeb6a1baeb32a411f2d7b7f7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9?= Date: Sun, 28 Sep 2025 18:28:55 +0500 Subject: [PATCH 3/5] =?UTF-8?q?=D0=9F=D0=BB=D0=BE=D1=82=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=9F=D1=80=D0=98-202=20=E2=80=94=20=D0=97=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task03/src/com/example/task03/ComplexNum.java | 43 +++++++++++++++++++ task03/src/com/example/task03/Task03Main.java | 6 +++ 2 files changed, 49 insertions(+) create mode 100644 task03/src/com/example/task03/ComplexNum.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..74b2c7ab --- /dev/null +++ b/task03/src/com/example/task03/ComplexNum.java @@ -0,0 +1,43 @@ +package com.example.task03; + +import java.text.MessageFormat; + +public class ComplexNum { + private double real; + private double imaginary; + + public ComplexNum() { + this(0, 0); + } + + public ComplexNum(double real, double imaginary) { + this.real = real; + this.imaginary = imaginary; + } + + public ComplexNum add(ComplexNum addable) { + return new ComplexNum(this.real + addable.real, + this.imaginary + addable.imaginary); + } + + public ComplexNum mult(ComplexNum multipliable) { + double realRes = this.real * multipliable.real - this.imaginary * multipliable.imaginary; + double imaginaryRes = this.real * multipliable.imaginary + this.imaginary * multipliable.real; + + return new ComplexNum(realRes, imaginaryRes); + } + + public String toString() { + if (imaginary == 0) { + return MessageFormat.format("{0,number,0.00}", real); + } else if (real == 0) { + return MessageFormat.format("{0,number,0.00}i", imaginary); + } else { + String sign = imaginary > 0 ? " + " : " - "; + double absImaginary = Math.abs(imaginary); + + return MessageFormat.format("{0,number,0.00}{1}{2,number,0.00}i", + real, sign, absImaginary); + } + } +} diff --git a/task03/src/com/example/task03/Task03Main.java b/task03/src/com/example/task03/Task03Main.java index ae40e6f2..30137336 100644 --- a/task03/src/com/example/task03/Task03Main.java +++ b/task03/src/com/example/task03/Task03Main.java @@ -1,7 +1,13 @@ package com.example.task03; +import java.text.MessageFormat; + public class Task03Main { public static void main(String[] args) { + ComplexNum num1 = new ComplexNum(5, -3.6); + ComplexNum num2 = new ComplexNum(1, 2); + System.out.println("Сумма комплексных чисел: " + num1.add(num2)); + System.out.println("Произведение комплексных чисел: " + num1.mult(num2)); } } From cc2b6327916b3f70d2f61534d96f97a1b1e00ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9?= Date: Sun, 28 Sep 2025 18:59:29 +0500 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9F=D0=BB=D0=BE=D1=82=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=9F=D1=80=D0=98-202=20=E2=80=94=20=D0=97=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task04/src/com/example/task04/Line.java | 63 +++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 task04/src/com/example/task04/Line.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..08e6d44b --- /dev/null +++ b/task04/src/com/example/task04/Line.java @@ -0,0 +1,63 @@ +package com.example.task04; + +import java.text.MessageFormat; + +public class Line { + private Point p1; + private Point p2; + + public Line(int p1X, int p1Y, int p2X, int p2Y) { + this.p1 = new Point(p1X, p1Y); + this.p2 = new Point(p2X, p2Y); + } + + private class Point { + private final int x; + private final int y; + + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + public Point() { + this(0, 0); + } + + double distance(Point point) { + int xDif = this.x - point.x; + int yDif = this.y - point.y; + return Math.sqrt(xDif * xDif + yDif * yDif); + } + + public String toString() { + return String.format("(%d, %d)", x, y); + } + + void print() { + System.out.println(this); + } + } + + public Point getP1() { + return p1; + } + + public Point getP2() { + return p2; + } + + public boolean isCollinearLine(Point p) { + int vectorX = p2.x - p1.x; + int vectorY = p2.y - p1.y; + + int vectorToP1X = p.x - p1.x; + int vectorToP1Y = p.y - p1.y; + + return vectorX * vectorToP1Y - vectorY * vectorToP1X == 0; + } + + public String toString() { + return MessageFormat.format("[{0};{1}]", p1, p2); + } +} From bd0456383ea2ab5e7847567781d12709f3e60843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9?= Date: Sun, 28 Sep 2025 20:18:04 +0500 Subject: [PATCH 5/5] =?UTF-8?q?=D0=9F=D0=BB=D0=BE=D1=82=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=93=D0=B5=D0=BE=D1=80=D0=B3=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=9F=D1=80=D0=98-202=20=E2=80=94=20=D0=97=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task05/src/com/example/task05/Point.java | 16 +++++++++------- .../src/com/example/task05/PolygonalLine.java | 17 ++++++++++++----- task05/src/com/example/task05/Task05Main.java | 9 ++++++++- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/task05/src/com/example/task05/Point.java b/task05/src/com/example/task05/Point.java index 968ea652..00c65dc7 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,9 @@ public double getY() { * @return расстояние от текущей точки до переданной */ public double getLength(Point point) { - // TODO: реализовать - throw new AssertionError(); + double xDif = this.x - point.x; + double yDif = this.y - point.y; + return Math.sqrt(xDif * xDif + yDif * yDif); } } diff --git a/task05/src/com/example/task05/PolygonalLine.java b/task05/src/com/example/task05/PolygonalLine.java index b534bfd5..22bb4f8d 100644 --- a/task05/src/com/example/task05/PolygonalLine.java +++ b/task05/src/com/example/task05/PolygonalLine.java @@ -1,9 +1,12 @@ package com.example.task05; +import java.util.ArrayList; + /** * Ломаная линия */ public class PolygonalLine { + private ArrayList points = new ArrayList(); /** * Устанавливает точки ломаной линии @@ -11,7 +14,8 @@ public class PolygonalLine { * @param points массив точек, которыми нужно проинициализировать ломаную линию */ public void setPoints(Point[] points) { - // TODO: реализовать + for (Point point : points) + addPoint(point); } /** @@ -20,7 +24,7 @@ public void setPoints(Point[] points) { * @param point точка, которую нужно добавить к ломаной */ public void addPoint(Point point) { - // TODO: реализовать + points.add(new Point(point.getX(), point.getY())); } /** @@ -30,7 +34,7 @@ public void addPoint(Point point) { * @param y координата по оси ординат */ public void addPoint(double x, double y) { - // TODO: реализовать + points.add(new Point(x, y)); } /** @@ -39,8 +43,11 @@ 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; } } diff --git a/task05/src/com/example/task05/Task05Main.java b/task05/src/com/example/task05/Task05Main.java index 4f745fb6..f6644f67 100644 --- a/task05/src/com/example/task05/Task05Main.java +++ b/task05/src/com/example/task05/Task05Main.java @@ -2,6 +2,13 @@ public class Task05Main { public static void main(String[] args) { - + PolygonalLine line = new PolygonalLine(); + line.setPoints(new Point[] { + new Point(1,2), + new Point(3,1), + new Point(5,6) + }); + line.addPoint(7, 1); + System.out.println("Длина ломаной линии: " + line.getLength()); } }