Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Vector {
- private double x;
- private double y;
- public Vector(double x, double y) {
- this.x = x;
- this.y = y;
- }
- @Override
- public String toString() {
- return "[" + x + "; " + y + "]";
- }
- public void scale(double num) {
- this.x *= num;
- this.y *= num;
- }
- public void add(Vector other) {
- this.x += other.x;
- this.y += other.y;
- }
- public double magnitude() {
- double mag = Math.sqrt(this.x * this.x + this.y * this.y);
- return mag;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement