about summary refs log tree commit diff
path: root/usth/ICT2.2/labwork/3/Java/Vector.java
blob: 3fc91379a0277501cdf2080678b9289f891932b3 (plain) (blame)
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
public class Vector
{
  // There's nothing to validate
  public int x;
  public int y;

  public Vector()
  {
    this(0, 0);
  }

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

  public String toString()
  {
    // I feel bad writing this
    return "(" + x + ", " + y + ")";
  }

  public Vector add(Vector other)
  {
    return new Vector(this.x + other.x, this.y + other.y);
  }

  public Vector subtract(Vector other)
  {
    return new Vector(this.x - other.x, this.y - other.y);
  }

  public Vector multiply(Vector other)
  {
    // instruction unclear, applying element-wise multiplication
    return new Vector(this.x * other.x, this.y * other.y);
  }
}