Advertisement
vencinachev

Class Vector

Mar 9th, 2021
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1. public class Vector {
  2.     private double x;
  3.     private double y;
  4.    
  5.     public Vector(double x, double y) {
  6.         this.x = x;
  7.         this.y = y;
  8.     }
  9.  
  10.     @Override
  11.     public String toString() {
  12.         return "[" + x + "; " + y + "]";
  13.     }
  14.    
  15.     public void scale(double num) {
  16.         this.x *= num;
  17.         this.y *= num;
  18.     }
  19.    
  20.     public void add(Vector other) {
  21.         this.x += other.x;
  22.         this.y += other.y;
  23.     }
  24.    
  25.     public double magnitude() {
  26.         double mag = Math.sqrt(this.x * this.x + this.y * this.y);
  27.         return mag;
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement