package ru kpfu itis group11402 batyrova Task053 import ru kpfu itis g

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ru.kpfu.itis.group11402.batyrova.Task053;
import ru.kpfu.itis.group11402.batyrova.Task050.RationalFraction;
/**
* @author Elvira Batyrova
* 402
* 053
*/
public class RationalVector2D {
private RationalFraction x;
private RationalFraction y;
public RationalFraction getX() {
return x;
}
public void setX(RationalFraction x) {
this.x = x;
}
public RationalFraction getY() {
return y;
}
public void setY(RationalFraction y) {
this.y = y;
}
public RationalVector2D() {
this(new RationalFraction(), new RationalFraction());
}
public RationalVector2D(RationalFraction x, RationalFraction y) {
this.x = x;
this.y = y;
}
public RationalVector2D add(RationalVector2D rvect) {
return new RationalVector2D (x.add(rvect.getX()), y.add(rvect.getY()));
}
public String toString() {
return ("(" + x.toString() + ", " + y.toString() + ")");
}
public double length() {
return Math.sqrt(x.value() * x.value() + y.value() * y.value());
}
public RationalFraction scalarProduct(RationalVector2D rvect) {
return x.mult(rvect.getX()).add(y.mult(rvect.getY()));
}
public boolean equals(RationalVector2D rvect) {
return (x.equals(rvect.getX()) && y.equals(rvect.getY()));
}
}