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
36 changes: 30 additions & 6 deletions task01/src/com/example/task01/Point.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
package com.example.task01;

/**
* Класс точки на плоскости
*/
public class Point {
public class Point
{
int x;
int y;

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

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); //d=√(Xb-Xa)^2+(Yb-Ya)^2)
}

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

void print()
{
String pointToString = String.format("(%d, %d)", x, y);
System.out.println(pointToString);
}
}
}
75 changes: 75 additions & 0 deletions task02/src/com/example/task02/TimeSpan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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;
this.hours = totalSecond / 3600;
this.minutes = (totalSecond % 3600) / 60;
this.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();
}

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

public class ComplexN
{
private final double realPart;
private final double imaginaryPart;

public ComplexN(double realPart, double imaginaryPart)
{
this.realPart = realPart;
this.imaginaryPart = imaginaryPart;
}

public double getRealPart()
{
return realPart;
}

public double getImaginaryPart()
{
return imaginaryPart;
}

public ComplexN add(ComplexN complexNumber)
{
double real = this.realPart + complexNumber.realPart;
double imaginary = this.imaginaryPart + complexNumber.imaginaryPart;
return new ComplexN(real, imaginary);
}

public ComplexN multiply(ComplexN complexNumber) //по формуле (a1+b1*i)(a2+b2*i)=(a1a2-b1b2)+(a1b2+a2b1)i
{
double real = this.realPart * complexNumber.realPart - this.imaginaryPart * complexNumber.imaginaryPart;
double imaginary = this.realPart * complexNumber.imaginaryPart + this.imaginaryPart * complexNumber.realPart;
return new ComplexN(real, imaginary);
}

@Override
public String toString() //для вывода на экран в стандартной форме
{
if (imaginaryPart >= 0)
{
return realPart + "+" + imaginaryPart + "i";
}
return realPart + "-" + (-imaginaryPart) + "i";
}
}
15 changes: 11 additions & 4 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.example.task03;

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

public class Task03Main
{
public static void main(String[] args)
{
ComplexN z1 = new ComplexN(1, 2);
ComplexN z2 = new ComplexN(-5, 3);
System.out.println(z1); //1+2i
System.out.println(z2); //-5+3i
System.out.println(z1.add(z2)); //-4+5i
System.out.println(z1.multiply(z1)); //-3+4i
}
}
}
34 changes: 34 additions & 0 deletions task04/src/com/example/task04/Line.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.task04;

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;
}

@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;
}
}
38 changes: 38 additions & 0 deletions task04/src/com/example/task04/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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;
}

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); //d=√(Xb-Xa)^2+(Yb-Ya)^2)
}

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

void print()
{
String pointToString = String.format("(%d, %d)", x, y);
System.out.println(pointToString);
}
}
59 changes: 20 additions & 39 deletions task05/src/com/example/task05/Point.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,30 @@
package com.example.task05;

/**
* Точка в двумерном пространстве
*/
public class Point {
public class Point
{
private final double x;
private final double y;

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

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

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

/**
* Подсчитывает расстояние от текущей точки до точки, переданной в качестве параметра
*
* @param point вторая точка отрезка
* @return расстояние от текущей точки до переданной
*/
public double getLength(Point point) {
// TODO: реализовать
throw new AssertionError();
public double getLength(Point point)
{
double a = Math.pow(x - point.x, 2);
double b = Math.pow(y - point.y, 2);
return Math.sqrt(a + b);
}

}
}
Loading