Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point2D {
- int x, y;
- public Point2D(int x, int y) {
- this.x = x;
- this.y = y;
- }
- double dist2D(Point2D p) {
- return (int)(Math.ceil( (float) Math.sqrt( (p.x - this.x) * (p.x - this.x) + (p.y - this.y) * (p.y - this.y) )));
- }
- void printDistance(double d) {
- System.out.println("2D distance = " + (int)d);
- }
- }
- class Point3D extends Point2D {
- int z;
- public Point3D(int x, int y) {
- this(x, y, 0);
- }
- public Point3D(int x, int y, int z) {
- super(x, y);
- this.z = z;
- }
- double dist3D(Point3D p) {
- return (int) (Math.ceil( (float) Math.sqrt( (p.x - this.x) * (p.x - this.x) + (p.y - this.y) * (p.y - this.y) + (p.z - this.z) * (p.z - this.z) )));
- }
- void printDistance(double d) {
- System.out.println("3D distance = " + (int)d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement