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
27 changes: 23 additions & 4 deletions task01/src/com/example/task01/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,27 @@ public class Point {
int x;
int y;

void print() {
String pointToString = String.format("(%d, %d)", x, y);
System.out.println(pointToString);
public Point(int x, int y) {
this.x = x;
this.y = y;
}


public void flip() {
int temp = x;

x = -y;
y = -temp;
}

public double distance(Point point) {
double a = Math.pow(x - point.x, 2);
double b = Math.pow(y - point.y, 2);

return Math.sqrt(a + b);
}

public String toString() {
return String.format("(%d, %d)", x, y);
}
}
}
12 changes: 4 additions & 8 deletions task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

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();
p1.toString();
System.out.println(p1);
System.out.println("Point 2:");
p2.print();
p2.toString();
System.out.println(p2);
}
}
2 changes: 2 additions & 0 deletions task02/src/com/example/task02/Task02Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public class Task02Main {
public static void main(String[] args) {

TimeSpan time = new TimeSpan(1, 100, 65);
System.out.println(time);
}
}
62 changes: 62 additions & 0 deletions task02/src/com/example/task02/TimeSpan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.example.task02;

public class TimeSpan {
private int Hours;
private int Minutes;
private int Seconds;

public TimeSpan(int hours, int minutes, int seconds) {
correctTimeFormat(hours, minutes, seconds);
}

private void correctTimeFormat(int hours, int minutes, int seconds) {
if (seconds > 59) {
minutes += seconds / 60;
seconds %= 60;
}
if (minutes > 59) {
hours += minutes / 60;
minutes %= 60;
}

Hours = hours;
Minutes = minutes;
Seconds = seconds;
}

public int getHours() {
return Hours;
}

public void setHours(int valueOfHours) {
Hours = valueOfHours;
}

public int getMinutes() {
return Minutes;
}

public void setMinutes(int valueOfMinutes) {
Minutes = valueOfMinutes;
}

public int getSeconds() {
return Seconds;
}

public void setSeconds(int valueOfSeconds) {
Seconds = valueOfSeconds;
}

public void add(TimeSpan time) {
correctTimeFormat(Hours + time.Hours, Minutes + time.Minutes, Seconds + time.Seconds);
}

public void subtract(TimeSpan time) {
correctTimeFormat(Math.abs(Hours - time.Hours), Math.abs(Minutes - time.Minutes), Math.abs(Seconds - time.Seconds));
}

public String toString() {
return String.format("%d:%d:%d", Hours, Minutes, Seconds);
}
}
28 changes: 28 additions & 0 deletions task03/src/com/example/task03/ComplexNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.task03;

public class ComplexNumber {
private final double RealPart;
private final double ImaginaryPart;

public ComplexNumber(double realPart, double imaginaryPart) {
RealPart = realPart;
ImaginaryPart = imaginaryPart;
}

public ComplexNumber summarizeComplexNumbers(ComplexNumber number) {
double realParts = RealPart + number.RealPart;
double imaginaryParts = ImaginaryPart + number.ImaginaryPart;
return new ComplexNumber(realParts, imaginaryParts);
}

public ComplexNumber multiplyComplexNumbers(ComplexNumber number) {
double a = RealPart * number.RealPart - ImaginaryPart * number.ImaginaryPart;
double b = RealPart * number.ImaginaryPart + ImaginaryPart * number.RealPart;
return new ComplexNumber(a, b);
}

public String toString() {
String complexOneUnit = "i";
return (ImaginaryPart > 0) ? RealPart + "+" + ImaginaryPart + complexOneUnit : RealPart + "" + ImaginaryPart + complexOneUnit;
}
}
6 changes: 6 additions & 0 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
public class Task03Main {
public static void main(String[] args) {

ComplexNumber num1 = new ComplexNumber(5, 4);
ComplexNumber num2 = new ComplexNumber(10, 6);
ComplexNumber sum = num1.summarizeComplexNumbers(num2);
ComplexNumber mul = num1.multiplyComplexNumbers(num2);
System.out.println(sum);
System.out.println(mul);
}
}
28 changes: 28 additions & 0 deletions task04/src/com/example/task04/Line.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.task04;

public class Line {
private final Point Start;
private final Point End;

public Line(Point start, Point end) {
Start = start;
End = end;
}

public Point getP1() {
return Start;
}

public Point getP2() {
return End;
}

public boolean isCollinearLine(Point p) {
return (End.x - Start.x) * (p.y - Start.y) - (p.x - Start.x) * (End.y - Start.y) == 0;
}

@Override
public String toString() {
return String.format("(%d, %d), (%d, %d)", Start.x, Start.y, End.x, End.y);
}
}
22 changes: 22 additions & 0 deletions task04/src/com/example/task04/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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;
}

public double distance(Point point) {
double a = Math.pow(x - point.x, 2);
double b = Math.pow(y - point.y, 2);

return Math.sqrt(a + b);
}

public String toString() {
return String.format("(%d, %d)", x, y);
}
}
7 changes: 7 additions & 0 deletions task04/src/com/example/task04/Task04Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

public class Task04Main {
public static void main(String[] args) {
Point start = new Point(1, 1);
Point end = new Point(3, 5);
Point point = new Point(4, 7);

Line line = new Line(start, end);
boolean result = line.isCollinearLine(point);

System.out.println(result);
}
}
35 changes: 17 additions & 18 deletions task05/src/com/example/task05/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
*/
public class Point {

/**
* Конструктор, инициализирующий координаты точки
*
* @param x координата по оси абсцисс
* @param y координата по оси ординат
*/
public Point(double x, double y) {
throw new AssertionError();
}
public class Point {
private final double X;
private final double Y;

/**
* Возвращает координату точки по оси абсцисс
*
* @return координату точки по оси X
*/
public Point(double x, double y){

X =x;
Y =y;
}
public double getX() {
// TODO: реализовать
throw new AssertionError();

return X;
}

/**
Expand All @@ -32,7 +26,8 @@ public double getX() {
*/
public double getY() {
// TODO: реализовать
throw new AssertionError();

return Y;
}

/**
Expand All @@ -43,7 +38,11 @@ public double getY() {
*/
public double getLength(Point point) {
// TODO: реализовать
throw new AssertionError();

double a = Math.pow(X - point.X, 2);
double b = Math.pow(Y - point.Y, 2);

return Math.sqrt(a + b);
}

}
38 changes: 20 additions & 18 deletions task05/src/com/example/task05/PolygonalLine.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package com.example.task05;

/**
* Ломаная линия
*/
import java.util.ArrayList;

public class PolygonalLine {
private final ArrayList<Point> Line;

/**
* Устанавливает точки ломаной линии
*
* @param points массив точек, которыми нужно проинициализировать ломаную линию
*/
public PolygonalLine() {
Line = new ArrayList<>();
}
public void setPoints(Point[] points) {
// TODO: реализовать
for (Point p : points) {
addPoint(p);
}

/**
* Добавляет точку к ломаной линии
*
* @param point точка, которую нужно добавить к ломаной
*/

public void addPoint(Point point) {
// TODO: реализовать
Line.add(new Point(point.getX(), point.getY()));
}

/**
Expand All @@ -30,7 +25,7 @@ public void addPoint(Point point) {
* @param y координата по оси ординат
*/
public void addPoint(double x, double y) {
// TODO: реализовать
Line.add(new Point(x, y));
}

/**
Expand All @@ -39,8 +34,15 @@ public void addPoint(double x, double y) {
* @return длину ломаной линии
*/
public double getLength() {
// TODO: реализовать
throw new AssertionError();

double lenght = 0;
for (int i = 0; i < Line.size() - 1; i++) {
Point first = Line.get(i);
Point second = Line.get(i + 1);
lenght += first.getLength(second);
}

return lenght;
}

}