So I am trying to create a program that gives the distances between two points that can be inputted by the user. And here has to be a default constructor to set x and y values to 0. Any help to set me in the right direction would be greatly appricated!
import java.util.*; import java.math.*; public class point { point P1=new point(0,0); point P2=new point(0,0); double x; double y; double getX() { return x; } double getY() { return y; } public void distance(double x, double y) { double p=Math.sqrt((P1.getX() - P2.getX()) * (P1.getX() - P2.getX()) + (P1.getY() - P2.getY()) * (P1.getY() - P2.getY()) ); } public double distance( double p) { distance(x,y); return p; } }
anddd the main...
import java.util.*; import java.math.*; public class Lab07 { public static void main(String[] args) { point P1=new point(0,0); point P2=new point(0,0); Scanner in = new Scanner(System.in); System.out.println("Enter first x coord"); double x = in.nextDouble(); System.out.println("Enter first y coord"); double y = in.nextDouble(); System.out.println("The distance between the two points is "+ point.distance(p)); } }