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
17 changes: 16 additions & 1 deletion task01/src/com/example/task01/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@
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);
Expand Down
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/ComplexNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.task03;

public class ComplexNumber {
private int real;
private int imaginary;

ComplexNumber(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 ComplexNumber add(ComplexNumber number) {
return new ComplexNumber(real + number.real, imaginary + number.imaginary);
}

public ComplexNumber mul(ComplexNumber number) {
return new ComplexNumber(real * number.real - imaginary * number.imaginary, imaginary * number.real + number.imaginary * real);
}

public String toString() {
return "(" + Integer.toString(real) + ", " + Integer.toString(imaginary) + "i" + ")";
}
}
5 changes: 4 additions & 1 deletion 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) {

ComplexNumber a = new ComplexNumber(1, 2);
ComplexNumber b = new ComplexNumber(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) + ")";
}

}
11 changes: 7 additions & 4 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 @@ -22,7 +25,7 @@ public Point(double x, double y) {
*/
public double getX() {
// TODO: реализовать
throw new AssertionError();
return x;
}

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

/**
Expand All @@ -43,7 +46,7 @@ public double getY() {
*/
public double getLength(Point point) {
// TODO: реализовать
throw new AssertionError();
return Math.sqrt((x - point.x) * (x - point.x) + (y - point.y) * (y - point.y));
}

}
14 changes: 13 additions & 1 deletion 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,11 @@ public class PolygonalLine {
*
* @param points массив точек, которыми нужно проинициализировать ломаную линию
*/
ArrayList<Point> points;
public void setPoints(Point[] points) {
// TODO: реализовать
for (Point point : points)
addPoint(point);
}

/**
Expand All @@ -21,6 +27,7 @@ public void setPoints(Point[] points) {
*/
public void addPoint(Point point) {
// TODO: реализовать
points.add(new Point(point.getX(), point.getY()));
}

/**
Expand All @@ -31,6 +38,7 @@ public void addPoint(Point point) {
*/
public void addPoint(double x, double y) {
// TODO: реализовать
points.add(new Point(x, y));
}

/**
Expand All @@ -40,7 +48,11 @@ public void addPoint(double x, double y) {
*/
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;
}

}