Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
22 changes: 17 additions & 5 deletions task01/src/com/example/task01/Point.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
70 changes: 70 additions & 0 deletions task02/src/com/example/task02/TimeSpan.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
39 changes: 39 additions & 0 deletions task03/src/com/example/task03/ComplexNum.java
Original file line number Diff line number Diff line change
@@ -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" + ")";
}
}
7 changes: 5 additions & 2 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
26 changes: 26 additions & 0 deletions task04/src/com/example/task04/Line.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 18 additions & 0 deletions task04/src/com/example/task04/Point.java
Original file line number Diff line number Diff line change
@@ -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) + ")";
}

}
16 changes: 8 additions & 8 deletions task05/src/com/example/task05/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -21,8 +24,7 @@ public Point(double x, double y) {
* @return координату точки по оси X
*/
public double getX() {
// TODO: реализовать
throw new AssertionError();
return x;
}

/**
Expand All @@ -31,8 +33,7 @@ public double getX() {
* @return координату точки по оси Y
*/
public double getY() {
// TODO: реализовать
throw new AssertionError();
return y;
}

/**
Expand All @@ -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));
}

}
}
24 changes: 17 additions & 7 deletions task05/src/com/example/task05/PolygonalLine.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.task05;

import java.util.ArrayList;
import java.util.Arrays;

/**
* Ломаная линия
*/
Expand All @@ -10,8 +13,13 @@ public class PolygonalLine {
*
* @param points массив точек, которыми нужно проинициализировать ломаную линию
*/
ArrayList<Point> points = new ArrayList<>(); // Инициализация ArrayList

public void setPoints(Point[] points) {
// TODO: реализовать
this.points.clear(); // Очищаем существующие точки
for (Point point : points) {
addPoint(point); // Добавляем копии точек
}
}

/**
Expand All @@ -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())); // Создаем копию точки
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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;
}

}
}