From ce44d0519fe7ceadd67fb13018d5ea9b70e66e11 Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Mon, 29 Sep 2025 22:37:57 +0500 Subject: [PATCH 01/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=97=D0=B0=D0=B4=D0=B0=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 | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/task01/src/com/example/task01/Point.java b/task01/src/com/example/task01/Point.java index ec5c69e8..3684f4a9 100644 --- a/task01/src/com/example/task01/Point.java +++ b/task01/src/com/example/task01/Point.java @@ -7,6 +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 item = x; + x = - y; + y = - item; + } + + double distance(Point point){ + double distanceX = point.x - this.x; + double distanceY = point.y - this.y; + double result = Math.sqrt((distanceX * distanceX) + (distanceY * distanceY)); + return result; + } + + public String toString(){ + return String.format("(%d, %d)", x, y); + } + void print() { String pointToString = String.format("(%d, %d)", x, y); System.out.println(pointToString); From d19fc825ce50e1501306d40391f010d051671e31 Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Tue, 30 Sep 2025 00:09:14 +0500 Subject: [PATCH 02/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=97=D0=B0=D0=B4=D0=B0=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 | 52 +++++++++++++++++++++ 1 file changed, 52 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..2f34c269 --- /dev/null +++ b/task02/src/com/example/task02/TimeSpan.java @@ -0,0 +1,52 @@ +package com.example.task02; + +public class TimeSpan { + + private int inHours; + private int inMinutes; + private int inSeconds; + + public TimeSpan( int hours, int minutes, int seconds){ + inHours = hours; + inMinutes = minutes; + inSeconds = seconds; + } + + public int GetHours(){ + return inHours; + } + public void SetHours(int inHours){ + this.inHours = inHours; + } + + public int GetMinutes(){ + return inMinutes; + } + public void SetMinutes(int inMinutes){ + this.inMinutes = inMinutes; + } + + public int GetSeconds(){ + return inSeconds; + } + public void SetSeconds(int inSeconds){ + this.inSeconds = inSeconds; + } + + void add(TimeSpan time){ + this.inHours += time.inHours; + this.inMinutes += time.inMinutes; + this.inSeconds += time.inSeconds; + } + + void subtract(TimeSpan time){ + this.inHours -= time.inHours; + this.inMinutes -= time.inMinutes; + this.inSeconds -= time.inSeconds; + } + + public String toString(){ + return String.format("Интервал времени: %d часов %d минут %d сек", inHours, inMinutes, inSeconds); + } + +} From d607832e311da43cb9ccf0342c754f2f5d14717b Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Tue, 30 Sep 2025 12:08:46 +0500 Subject: [PATCH 03/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=202.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task02/src/com/example/task02/Task02Main.java | 25 ++++++++ task02/src/com/example/task02/TimeSpan.java | 60 ++++++++++++++++--- 2 files changed, 76 insertions(+), 9 deletions(-) diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index 644a0eba..465ac01c 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -2,6 +2,31 @@ public class Task02Main { public static void main(String[] args) { + TimeSpan time1 = new TimeSpan(1,100,130); + System.out.println("Время 1" + time1); + TimeSpan time2 = new TimeSpan(0,90,0); + System.out.println("Время 2" + time2); + System.out.println("Часы: " + time1.getHours()); + System.out.println("Минуты: " + time1.getMinutes()); + System.out.println("Секунды: " + time1.getSeconds()); + + time1.setMinutes(75); + System.out.println("После установки значения: " + time1); + System.out.println("Минуты: " + time1.getMinutes()); + + TimeSpan time3 = new TimeSpan(1, 30, 0); + TimeSpan time4 = new TimeSpan(0, 45, 30); + + time3.add(time4); + System.out.println("После метода .add: " + time3); + + TimeSpan time5 = new TimeSpan(2, 0, 0); + TimeSpan time6 = new TimeSpan(0, 45, 0); + System.out.println("Время 5: " + time5); + System.out.println("Время 6: " + time6); + + time5.subtract(time6); + System.out.println("После метода .subtract: " + time5); } } diff --git a/task02/src/com/example/task02/TimeSpan.java b/task02/src/com/example/task02/TimeSpan.java index 2f34c269..28ebbcdb 100644 --- a/task02/src/com/example/task02/TimeSpan.java +++ b/task02/src/com/example/task02/TimeSpan.java @@ -10,43 +10,85 @@ public TimeSpan( int hours, int minutes, int seconds){ inHours = hours; inMinutes = minutes; inSeconds = seconds; + transformTime(); } - public int GetHours(){ + public int getHours(){ return inHours; } - public void SetHours(int inHours){ + public void setHours(int inHours){ + if (inHours < 0) { + throw new IllegalArgumentException("Часы не могут быть отрицательными"); + } this.inHours = inHours; } - public int GetMinutes(){ + public int getMinutes(){ return inMinutes; } - public void SetMinutes(int inMinutes){ + public void setMinutes(int inMinutes){ + if (inMinutes < 0) { + throw new IllegalArgumentException("Минуты не могут быть отрицательными"); + } this.inMinutes = inMinutes; + transformTime(); } - public int GetSeconds(){ + public int getSeconds(){ return inSeconds; } - public void SetSeconds(int inSeconds){ + public void setSeconds(int inSeconds){ + if (inSeconds < 0) { + throw new IllegalArgumentException("Секунды не могут быть отрицательными"); + } this.inSeconds = inSeconds; + transformTime(); } - void add(TimeSpan time){ + private void transformTime(){ + if(inSeconds >= 60) { + inMinutes += inSeconds / 60; + inSeconds %= 60; + } + + if (inMinutes >= 60){ + inHours += inMinutes / 60; + inMinutes %= 60; + } + + // Обрабатываем отрицательные секунды + if (inSeconds < 0){ + inSeconds = - inSeconds; + int borrowMinutes = (inSeconds + 59) / 60; + inMinutes -= borrowMinutes; + inSeconds = (borrowMinutes * 60) - inSeconds; + } + + // Обрабатываем отрицательные минуты + if(inMinutes < 0){ + inMinutes = -inMinutes; + int borrowHours = (inMinutes + 59) / 60; + inHours -= borrowHours; + inMinutes = (borrowHours * 60) - inMinutes; + } + } + + public void add(TimeSpan time){ this.inHours += time.inHours; this.inMinutes += time.inMinutes; this.inSeconds += time.inSeconds; + transformTime(); } - void subtract(TimeSpan time){ + public void subtract(TimeSpan time){ this.inHours -= time.inHours; this.inMinutes -= time.inMinutes; this.inSeconds -= time.inSeconds; + transformTime(); // также исправляет отрицательное значение } public String toString(){ - return String.format("Интервал времени: %d часов %d минут %d сек", inHours, inMinutes, inSeconds); + return String.format("Временной интервал: %d ч %d мин %d сек", inHours, inMinutes, inSeconds); } } From c2adcf7660276e8a1b735faa64898889b397b503 Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Tue, 30 Sep 2025 13:50:44 +0500 Subject: [PATCH 04/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/task03/ComplexNumbers.java | 41 +++++++++++++++++++ task03/src/com/example/task03/Task03Main.java | 7 ++++ 2 files changed, 48 insertions(+) create mode 100644 task03/src/com/example/task03/ComplexNumbers.java diff --git a/task03/src/com/example/task03/ComplexNumbers.java b/task03/src/com/example/task03/ComplexNumbers.java new file mode 100644 index 00000000..2eb93bb4 --- /dev/null +++ b/task03/src/com/example/task03/ComplexNumbers.java @@ -0,0 +1,41 @@ +package com.example.task03; + +public class ComplexNumbers { + + private final double realPart; + private final double imaginaryPart; + + public ComplexNumbers( double realPart, double imaginaryPart){ + this.realPart = realPart; + this.imaginaryPart = imaginaryPart; + } + + public ComplexNumbers add(ComplexNumbers comples){ + return new ComplexNumbers( + this.realPart + comples.realPart, + this.imaginaryPart + comples.imaginaryPart); + } + + public ComplexNumbers product(ComplexNumbers complex){ + double newReal = (this.realPart * complex.realPart) - (this.imaginaryPart * complex.imaginaryPart); + double newImaginary = this.realPart * complex.imaginaryPart + this.imaginaryPart * complex.realPart; + return new ComplexNumbers(newReal, newImaginary); + } + + public String toString() { + if (realPart == 0) { + // Только мнимая часть + if (imaginaryPart == 0) { + return String.format("Комплексное число: 0"); + } else { + return String.format("Комплексное число: %.2fi", imaginaryPart); + } + } else if (imaginaryPart > 0) { + return String.format("Комплексное число: %.2f + %.2fi", realPart, imaginaryPart); + } else if (imaginaryPart == 0) { + return String.format("Комплексное число: %.2f", realPart); + } else { + return String.format("Комплексное число: %.2f - %.2fi", realPart, Math.abs(imaginaryPart)); + } + } +} diff --git a/task03/src/com/example/task03/Task03Main.java b/task03/src/com/example/task03/Task03Main.java index ae40e6f2..fb49b20c 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) { + ComplexNumbers complex1 = new ComplexNumbers(0,2); + ComplexNumbers complex2 = new ComplexNumbers(1,-4); + System.out.println(complex1); + System.out.println(complex2); + + System.out.println(complex1.add(complex2)); + System.out.println(complex1.product(complex2)); } } From 58af0abe7f61bd6c75320b63f464b06802793484 Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Sun, 12 Oct 2025 23:44:53 +0500 Subject: [PATCH 05/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=97=D0=B0=D0=B4=D0=B0=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 | 52 +++++++++++++++++++ task04/src/com/example/task04/Task04Main.java | 15 ++++++ 2 files changed, 67 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..5a1b6e11 --- /dev/null +++ b/task04/src/com/example/task04/Line.java @@ -0,0 +1,52 @@ +package com.example.task04; + +import java.awt.*; + +class Point{ + public final int x; + public final int y; + + public Point(int x, int y){ + this.x = x; + this.y = y; + } + + public String toString() { + return "(" + x + ", " + y + ")"; + } +} + +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 String toString(){ + return String.format("Отрезок с началом в (%d, %d) и с концом в (%d, %d)", + p1.x, p1.y, p2.x, p2.y); + } + + public boolean isCollinearLine(Point p){ + + int x = p.x; + int y = p.y; + int area = (x - p1.x) * (p2.y - p1.y) - (y - p1.y) * (p2.x - p1.x); + return area == 0; + } + +} diff --git a/task04/src/com/example/task04/Task04Main.java b/task04/src/com/example/task04/Task04Main.java index 55917a30..a728c33e 100644 --- a/task04/src/com/example/task04/Task04Main.java +++ b/task04/src/com/example/task04/Task04Main.java @@ -3,5 +3,20 @@ public class Task04Main { public static void main(String[] args) { + Point p1 = new Point(1,1); + Point p2 = new Point(4,5); + Line section = new Line(p1,p2); + + Point startingPoint = section.getP1(); + Point enddingPoint = section.getP2(); + + System.out.println("Начало отрезка - " + startingPoint); + System.out.println("Конец отрезка - " + enddingPoint); + + System.out.println(section); + + Point p3 = new Point(2,3); + System.out.println("Точка" + p3 + " на прямой: " + section.isCollinearLine(p3)); + } } From b127267a907c5bff890aa3792c8e15144a0770a0 Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Mon, 13 Oct 2025 17:54:18 +0500 Subject: [PATCH 06/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=97=D0=B0=D0=B4=D0=B0=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 | 15 +++-- .../src/com/example/task05/PolygonalLine.java | 55 ++++++++++++++++++- task05/src/com/example/task05/Task05Main.java | 10 ++++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/task05/src/com/example/task05/Point.java b/task05/src/com/example/task05/Point.java index 968ea652..1cb4d94a 100644 --- a/task05/src/com/example/task05/Point.java +++ b/task05/src/com/example/task05/Point.java @@ -4,7 +4,8 @@ * Точка в двумерном пространстве */ public class Point { - + private final double x; + private final double y; /** * Конструктор, инициализирующий координаты точки * @@ -12,7 +13,8 @@ public class Point { * @param y координата по оси ординат */ public Point(double x, double y) { - throw new AssertionError(); + this.x = x; + this.y = y; } /** @@ -22,7 +24,7 @@ public Point(double x, double y) { */ public double getX() { // TODO: реализовать - throw new AssertionError(); + return x; } /** @@ -32,7 +34,7 @@ public double getX() { */ public double getY() { // TODO: реализовать - throw new AssertionError(); + return y; } /** @@ -43,7 +45,8 @@ public double getY() { */ public double getLength(Point point) { // TODO: реализовать - throw new AssertionError(); + double deltaX = this.x - point.x; + double deltaY = this.y - point.y; + return Math.sqrt(deltaX * deltaX + deltaY * deltaY); } - } diff --git a/task05/src/com/example/task05/PolygonalLine.java b/task05/src/com/example/task05/PolygonalLine.java index b534bfd5..d5077dee 100644 --- a/task05/src/com/example/task05/PolygonalLine.java +++ b/task05/src/com/example/task05/PolygonalLine.java @@ -1,10 +1,33 @@ package com.example.task05; +import sun.security.util.Length; +import java.util.ArrayList; +import java.util.List; /** * Ломаная линия */ public class PolygonalLine { + private Point[] points; + + public PolygonalLine() { + this.points = new Point[0]; // Создаем пустой массив точек + } + + public PolygonalLine(Point[] points) { + if (points == null) { + this.points = new Point[0]; + } else { + this.points = new Point[points.length]; + + for (int i = 0; i < points.length; i++){ + if(points[i] != null){ + this.points[i] = new Point(points[i].getX(), points[i].getY()); + } + } + } + } + /** * Устанавливает точки ломаной линии * @@ -12,6 +35,16 @@ public class PolygonalLine { */ public void setPoints(Point[] points) { // TODO: реализовать + if (points == null) { + this.points = new Point[0]; + } else { + this.points = new Point[points.length]; + for (int i = 0; i < points.length; i++) { + if (points[i] != null) { + this.points[i] = new Point(points[i].getX(), points[i].getY()); + } + } + } } /** @@ -21,6 +54,17 @@ public void setPoints(Point[] points) { */ public void addPoint(Point point) { // TODO: реализовать + if (point == null) return; + + Point newPoin = new Point(point.getX(), point.getY()); + + Point[] newPoint = new Point[points.length+1]; + + for (int i = 0; i < points.length; i++){ + newPoint[i] = points[i]; + } + newPoint[points.length] = newPoin; + points = newPoint; } /** @@ -31,6 +75,8 @@ public void addPoint(Point point) { */ public void addPoint(double x, double y) { // TODO: реализовать + Point point = new Point(x, y); + addPoint(point); } /** @@ -40,7 +86,14 @@ public void addPoint(double x, double y) { */ public double getLength() { // TODO: реализовать - throw new AssertionError(); + if (points.length < 2) return 0.0; + + double lineLength = 0.0; + + for (int i = 0; i < points.length - 1; i++){ + lineLength += points[i].getLength(points[i + 1]); + } + return lineLength; } } diff --git a/task05/src/com/example/task05/Task05Main.java b/task05/src/com/example/task05/Task05Main.java index 4f745fb6..ee2b4e8c 100644 --- a/task05/src/com/example/task05/Task05Main.java +++ b/task05/src/com/example/task05/Task05Main.java @@ -3,5 +3,15 @@ public class Task05Main { public static void main(String[] args) { + PolygonalLine line = new PolygonalLine(); + line.setPoints(new Point[]{ + new Point(2,3), + new Point(4,4), + new Point(1,3), + new Point(7,2) + }); + line.addPoint(0,5); + System.out.println("Длина ломаной: " + line.getLength()); + } } From adac4113268adc7220aacf9785e8071ea5dba569 Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Mon, 17 Nov 2025 21:53:50 +0500 Subject: [PATCH 07/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=201=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task01/src/com/example/task01/Point.java | 3 +-- task01/src/com/example/task01/Task01Main.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/task01/src/com/example/task01/Point.java b/task01/src/com/example/task01/Point.java index 3684f4a9..44666728 100644 --- a/task01/src/com/example/task01/Point.java +++ b/task01/src/com/example/task01/Point.java @@ -34,7 +34,6 @@ public String toString(){ } void print() { - String pointToString = String.format("(%d, %d)", x, y); - System.out.println(pointToString); + System.out.println(toString()); } } diff --git a/task01/src/com/example/task01/Task01Main.java b/task01/src/com/example/task01/Task01Main.java index 7d71173a..137e7cd3 100644 --- a/task01/src/com/example/task01/Task01Main.java +++ b/task01/src/com/example/task01/Task01Main.java @@ -2,18 +2,22 @@ public class Task01Main { public static void main(String[] args) { - Point p1 = new Point(); - p1.x = 10; - p1.y = 45; + Point p1 = new Point(10,45); + p1.x = 11; + p1.y = 46; Point p2 = new Point(); p2.x = 78; p2.y = 12; + p1.flip(); + System.out.println(p1); + + System.out.println(p1.distance(p2)); + + System.out.println("Point 1:"); - p1.print(); System.out.println(p1); System.out.println("Point 2:"); - p2.print(); System.out.println(p2); } } From 2a70779e6f75f1a2a75a7c613e759af1b42b156f Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Mon, 17 Nov 2025 23:45:45 +0500 Subject: [PATCH 08/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=202=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= 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 | 88 +++++++++++-------- 2 files changed, 53 insertions(+), 38 deletions(-) diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index 465ac01c..c5ed0f34 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -3,6 +3,7 @@ public class Task02Main { public static void main(String[] args) { TimeSpan time1 = new TimeSpan(1,100,130); + time1.setSeconds(3000); System.out.println("Время 1" + time1); TimeSpan time2 = new TimeSpan(0,90,0); System.out.println("Время 2" + time2); @@ -15,7 +16,7 @@ public static void main(String[] args) { System.out.println("После установки значения: " + time1); System.out.println("Минуты: " + time1.getMinutes()); - TimeSpan time3 = new TimeSpan(1, 30, 0); + TimeSpan time3 = new TimeSpan(-1, 30, 0); TimeSpan time4 = new TimeSpan(0, 45, 30); time3.add(time4); diff --git a/task02/src/com/example/task02/TimeSpan.java b/task02/src/com/example/task02/TimeSpan.java index 28ebbcdb..058bd58b 100644 --- a/task02/src/com/example/task02/TimeSpan.java +++ b/task02/src/com/example/task02/TimeSpan.java @@ -6,89 +6,103 @@ public class TimeSpan { private int inMinutes; private int inSeconds; - public TimeSpan( int hours, int minutes, int seconds){ - inHours = hours; - inMinutes = minutes; - inSeconds = seconds; - transformTime(); + public TimeSpan(int hours, int minutes, int seconds) { + if (hours < 0 || minutes < 0 || seconds < 0) { + throw new IllegalArgumentException("Все компоненты временного интервала должны быть неотрицательными"); + } + this.inHours = hours; + this.inMinutes = minutes; + this.inSeconds = seconds; + transformTime(); // на случай, если минут/секунд ≥ 60 } - public int getHours(){ + public int getHours() { return inHours; } - public void setHours(int inHours){ - if (inHours < 0) { + + public void setHours(int hours) { + if (hours < 0) { throw new IllegalArgumentException("Часы не могут быть отрицательными"); } - this.inHours = inHours; + this.inHours = hours; + transformTime(); // на случай нормализации полей } - public int getMinutes(){ + public int getMinutes() { return inMinutes; } - public void setMinutes(int inMinutes){ - if (inMinutes < 0) { + + public void setMinutes(int minutes) { + if (minutes < 0) { throw new IllegalArgumentException("Минуты не могут быть отрицательными"); } - this.inMinutes = inMinutes; + this.inMinutes = minutes; transformTime(); } - public int getSeconds(){ + public int getSeconds() { return inSeconds; } - public void setSeconds(int inSeconds){ - if (inSeconds < 0) { + + public void setSeconds(int seconds) { + if (seconds < 0) { throw new IllegalArgumentException("Секунды не могут быть отрицательными"); } - this.inSeconds = inSeconds; + this.inSeconds = seconds; transformTime(); } - private void transformTime(){ - if(inSeconds >= 60) { + private void transformTime() { + // Обработка секунд + if (inSeconds >= 60) { inMinutes += inSeconds / 60; inSeconds %= 60; + } else if (inSeconds < 0) { + int borrow = (-inSeconds + 59) / 60; // сколько минут занять + inMinutes -= borrow; + inSeconds += borrow * 60; } - if (inMinutes >= 60){ + // Обработка минут + if (inMinutes >= 60) { inHours += inMinutes / 60; inMinutes %= 60; + } else if (inMinutes < 0) { + int borrow = (-inMinutes + 59) / 60; // сколько часов занять + inHours -= borrow; + inMinutes += borrow * 60; } - // Обрабатываем отрицательные секунды - if (inSeconds < 0){ - inSeconds = - inSeconds; - int borrowMinutes = (inSeconds + 59) / 60; - inMinutes -= borrowMinutes; - inSeconds = (borrowMinutes * 60) - inSeconds; + if (inHours < 0) { + throw new IllegalStateException("Нельзя получить отрицательный временной интервал: результат вычитания недопустим"); } - // Обрабатываем отрицательные минуты - if(inMinutes < 0){ - inMinutes = -inMinutes; - int borrowHours = (inMinutes + 59) / 60; - inHours -= borrowHours; - inMinutes = (borrowHours * 60) - inMinutes; + // на случай переносов после заимствований + if (inMinutes >= 60) { + inHours += inMinutes / 60; + inMinutes %= 60; + } + if (inSeconds >= 60) { + inMinutes += inSeconds / 60; + inSeconds %= 60; } } - public void add(TimeSpan time){ + public void add(TimeSpan time) { this.inHours += time.inHours; this.inMinutes += time.inMinutes; this.inSeconds += time.inSeconds; transformTime(); } - public void subtract(TimeSpan time){ + public void subtract(TimeSpan time) { this.inHours -= time.inHours; this.inMinutes -= time.inMinutes; this.inSeconds -= time.inSeconds; - transformTime(); // также исправляет отрицательное значение + transformTime(); } - public String toString(){ + public String toString() { return String.format("Временной интервал: %d ч %d мин %d сек", inHours, inMinutes, inSeconds); } - } From b4851a50936ef23c01670f613a5b21c5136ad344 Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Mon, 17 Nov 2025 23:51:42 +0500 Subject: [PATCH 09/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=201-2=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task02/src/com/example/task02/Task02Main.java | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index c5ed0f34..d6faccf0 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -3,31 +3,13 @@ public class Task02Main { public static void main(String[] args) { TimeSpan time1 = new TimeSpan(1,100,130); + System.out.println("Время 1 до "); + System.out.println(time1); time1.setSeconds(3000); - System.out.println("Время 1" + time1); - TimeSpan time2 = new TimeSpan(0,90,0); - System.out.println("Время 2" + time2); + System.out.println("Время 1 после"); + System.out.println(time1); - System.out.println("Часы: " + time1.getHours()); - System.out.println("Минуты: " + time1.getMinutes()); - System.out.println("Секунды: " + time1.getSeconds()); + time1.setSeconds(-1); - time1.setMinutes(75); - System.out.println("После установки значения: " + time1); - System.out.println("Минуты: " + time1.getMinutes()); - - TimeSpan time3 = new TimeSpan(-1, 30, 0); - TimeSpan time4 = new TimeSpan(0, 45, 30); - - time3.add(time4); - System.out.println("После метода .add: " + time3); - - TimeSpan time5 = new TimeSpan(2, 0, 0); - TimeSpan time6 = new TimeSpan(0, 45, 0); - System.out.println("Время 5: " + time5); - System.out.println("Время 6: " + time6); - - time5.subtract(time6); - System.out.println("После метода .subtract: " + time5); } } From d02d9f46213f6fc9995154dc409b2245c42dbb27 Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Tue, 18 Nov 2025 00:49:13 +0500 Subject: [PATCH 10/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=201-3=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/example/task03/ComplexNumbers.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/task03/src/com/example/task03/ComplexNumbers.java b/task03/src/com/example/task03/ComplexNumbers.java index 2eb93bb4..97497643 100644 --- a/task03/src/com/example/task03/ComplexNumbers.java +++ b/task03/src/com/example/task03/ComplexNumbers.java @@ -23,19 +23,16 @@ public ComplexNumbers product(ComplexNumbers complex){ } public String toString() { - if (realPart == 0) { - // Только мнимая часть - if (imaginaryPart == 0) { - return String.format("Комплексное число: 0"); - } else { - return String.format("Комплексное число: %.2fi", imaginaryPart); - } - } else if (imaginaryPart > 0) { - return String.format("Комплексное число: %.2f + %.2fi", realPart, imaginaryPart); + if (realPart == 0 && imaginaryPart == 0) { + return "Комплексное число: 0"; + } else if (realPart == 0) { + return String.format("Комплексное число: %.2fi", imaginaryPart); } else if (imaginaryPart == 0) { return String.format("Комплексное число: %.2f", realPart); + } else if (imaginaryPart > 0) { + return String.format("Комплексное число: %.2f + %.2fi", realPart, imaginaryPart); } else { - return String.format("Комплексное число: %.2f - %.2fi", realPart, Math.abs(imaginaryPart)); + return String.format("Комплексное число: %.2f - %.2fi", realPart, -imaginaryPart); } } } From 73e0f9bf91d9b8fb272bdf94eaf93037e0c868eb Mon Sep 17 00:00:00 2001 From: Elaiza-art Date: Tue, 18 Nov 2025 09:08:04 +0500 Subject: [PATCH 11/11] =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D1=87=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=95=D0=BB=D0=B8=D0=B7=D0=B0=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0.=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=201-4=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task04/src/com/example/task04/Line.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/task04/src/com/example/task04/Line.java b/task04/src/com/example/task04/Line.java index 5a1b6e11..9758333c 100644 --- a/task04/src/com/example/task04/Line.java +++ b/task04/src/com/example/task04/Line.java @@ -3,14 +3,17 @@ import java.awt.*; class Point{ - public final int x; - public final int y; + 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; } + public String toString() { return "(" + x + ", " + y + ")"; } @@ -38,14 +41,14 @@ public Point getP2(){ public String toString(){ return String.format("Отрезок с началом в (%d, %d) и с концом в (%d, %d)", - p1.x, p1.y, p2.x, p2.y); + p1.getX(), p1.getY(), p2.getX(), p2.getY()); } public boolean isCollinearLine(Point p){ - int x = p.x; - int y = p.y; - int area = (x - p1.x) * (p2.y - p1.y) - (y - p1.y) * (p2.x - p1.x); + int x = p.getX(); + int y = p.getY(); + int area = (x - p1.getX()) * (p2.getY() - p1.getY()) - (y - p1.getY()) * (p2.getX() - p1.getX()); return area == 0; }