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

public Point() {
x = 0;
y = 0;
}

public Point(int x, int y){
this.x = x;
this.y = y;
}

void flip(){
int temp = x;
x = -y;
y = -temp;
}

double distance(Point point){
double distX = Math.pow(x-point.x,2);
double distY = Math.pow(y-point.y,2);
return Math.sqrt(distY + distX);
}

public String toString(){
return String.format("%d %d",x, y);
}

void print() {
String pointToString = String.format("(%d, %d)", x, y);
System.out.println(pointToString);
Expand Down
7 changes: 6 additions & 1 deletion task02/src/com/example/task02/Task02Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

public class Task02Main {
public static void main(String[] args) {

TimeSpan time1 = new TimeSpan(1,654,340);
TimeSpan time2 = new TimeSpan(0,34,1);
time1.add(time2);
System.out.println(time1.toString());
time1.setSeconds(60);
System.out.println(time1.toString());
}
}
66 changes: 66 additions & 0 deletions task02/src/com/example/task02/TimeSpan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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;
this.minutes = minutes;
this.seconds = seconds;
correctTime();
}
public int getHours() {
return hours;
}

public int getMinutes() {
return minutes;
}

public int getSeconds() {
return seconds;
}

public void setHours(int hours) {
this.hours = hours;
correctTime();
}

public void setMinutes(int minutes) {
this.minutes = minutes;
correctTime();
}

public void setSeconds(int seconds) {
this.seconds = seconds;
correctTime();
}

private void correctTime() {
int totalSecond = hours * 3600 + minutes * 60 + seconds;
hours = totalSecond / 3600;
minutes = (totalSecond % 3600) / 60;
seconds = (totalSecond % 3600) % 60;
}

void add(TimeSpan time) {
this.hours += time.hours;
this.minutes += time.minutes;
this.seconds += time.seconds;
correctTime();
}

void subtract(TimeSpan time) {
this.hours -= time.hours;
this.minutes -= time.minutes;
this.seconds -= time.seconds;
correctTime();
}

@Override
public String toString() {
return hours + ":" + minutes + ":" + seconds;
}
}
40 changes: 40 additions & 0 deletions task03/src/com/example/task03/ComplexNum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.task03;

public class ComplexNum {
private final double rePart;
private final double imPart;

public double getImPart() {
return imPart;
}

public double getRePart() {
return rePart;
}

public ComplexNum(double dPart, double mPart){
this.rePart = dPart;
this.imPart = mPart;
}

public ComplexNum Reverse(ComplexNum num){
return new ComplexNum(num.rePart,-num.imPart);
}

public ComplexNum Add(ComplexNum num){
return new ComplexNum(rePart + num.imPart, imPart + num.imPart);
}

public ComplexNum Multiply(ComplexNum num){
return new ComplexNum((rePart*num.rePart - imPart*num.imPart),(rePart*num.imPart + imPart*num.rePart));
}

@Override
public String toString(){
if(imPart>=0){
return rePart + "+" + imPart + "i";
}
return rePart + "-" + imPart + "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) {

ComplexNum num1 = new ComplexNum(10,12);
ComplexNum num2 = new ComplexNum(2,-4);
System.out.println(num1.Multiply(num2));
System.out.println(num1.Add(num2));
}
}
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 Point p1;
private Point p2;

public Line(Point p1, Point p2){
this.p1 = p1;
this.p2 = p2;
}

public Point getP1(){
return p1;
}

public Point getP2(){
return p2;
}

@Override
public String toString(){
return String.format("(%d,%d),(%d,%d)",p1.x,p1.y,p2.x,p2.y);
}

public boolean isCollinearLine(Point p) {
return (p2.x - p1.x) * (p.y - p1.y) - (p.x - p1.x) * (p2.y - p1.y) == 0;
}
}
30 changes: 30 additions & 0 deletions task04/src/com/example/task04/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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;
}

double distance(Point point){
double distX = Math.pow(x-point.x,2);
double distY = Math.pow(y-point.y,2);
return Math.sqrt(distY + distX);
}

public String toString(){
return String.format("%d %d",x, y);
}

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

7 changes: 6 additions & 1 deletion task04/src/com/example/task04/Task04Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

public class Task04Main {
public static void main(String[] args) {

Point p1 = new Point(1,1);
Point p2 = new Point(2,2);
Line linux = new Line(p1,p2);
System.out.println(linux.isCollinearLine(new Point(3,3)));
}
}


21 changes: 12 additions & 9 deletions task05/src/com/example/task05/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@
* Точка в двумерном пространстве
*/
public class Point {
final private double x;
final private double y;

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


/**
* Возвращает координату точки по оси абсцисс
*
* @return координату точки по оси X
*/
public double getX() {
// TODO: реализовать
throw new AssertionError();
return x;
}

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

/**
Expand All @@ -42,8 +44,9 @@ public double getY() {
* @return расстояние от текущей точки до переданной
*/
public double getLength(Point point) {
// TODO: реализовать
throw new AssertionError();
double distX = Math.pow(x-point.x,2);
double distY = Math.pow(y-point.y,2);
return Math.sqrt(distY + distX);
}

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

import java.util.ArrayList;

/**
* Ломаная линия
*/
public class PolygonalLine {
private ArrayList<Point> line = new ArrayList<Point>();

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

/**
Expand All @@ -20,7 +25,7 @@ public void setPoints(Point[] points) {
* @param point точка, которую нужно добавить к ломаной
*/
public void addPoint(Point point) {
// TODO: реализовать
line.add(new Point(point.getX(), point.getY()));
}

/**
Expand All @@ -30,7 +35,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 +44,13 @@ public void addPoint(double x, double y) {
* @return длину ломаной линии
*/
public double getLength() {
// TODO: реализовать
throw new AssertionError();
double lengthOfLine = 0;
for (int i = 0; i < line.size() - 1; i++) {
Point first = line.get(i);
Point second = line.get(i+1);
lengthOfLine += first.getLength(second);
}
return lengthOfLine;
}

}