c:\ece538>java Vec2Test A = (2.00000 3.00000) B = (-1.00000 1.00000) |
Vec2Test.java
// Creating and manipulating a Vec2 object import java.util.Scanner; public class Vec2Test { public static void main(String[] args) { Vec2 A = new Vec2("A",2.0,3.0); Vec2 B = new Vec2("B",-1.0,1.0); //Vec2 C = new Vec2(); // This statement generates a compile error if uncommented printVec2(A); printVec2(B); } static void printVec2(Vec2 V) { System.out.printf("%s = (%g %g)%n",V.getName(),V.getX(),V.getY()); } }
Vec2.java
// Vec2 class that contains private instance variables public class Vec2 { private String name; private double kx, ky; public Vec2(String name, double kx, double ky) { this.name = name; this.kx = kx; this.ky = ky; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setVec(double kx, double ky) { this.kx = kx; this.ky = ky; } public double getX() { return kx; } public double getY() { return ky; } }
Maintained by John Loomis, updated Thu Jan 16 19:07:02 2020