import java.util.*;
import java.lang.Math;
public class TestPoint{
public static void main(String[] args){
System.out.println("please enter the x,y,z of a point:");
Scanner inX = new Scanner(System.in);
double inputX = inX.nextDouble();
Scanner inY = new Scanner(System.in);
double inputY = inX.nextDouble();
Scanner inZ = new Scanner(System.in);
double inputZ = inX.nextDouble();
System.out.println("the point you just have inputed is : x = " + inputX + ", y = " + inputY + ", z = " + inputZ);
Point p1 = new Point(inputX, inputY, inputZ);
System.out.println("the distance is :" + p1.getDistance(p1));
System.out.println("do you wanna change the value of x, y, z, do you? ");
Scanner in = new Scanner(System.in);
String inIf = in.next();
String YES = "YES";
if(inIf == YES){
Scanner chX = new Scanner(System.in);
double changeX = chX.nextDouble();
Scanner chY = new Scanner(System.in);
double changeY = chY.nextDouble();
Scanner chZ = new Scanner(System.in);
double changeZ = chZ.nextDouble();
p1.modifyPoint(changeX, changeY, changeZ);
System.out.println("the distance after modified is :" + p1.getDistance(p1));
}
else{
System.exit(0);
}
}
}
class Point{
Point(double x, double y, double z){
this.x = x;
this.y = y;
this.z = z;
}
public void modifyPoint(double _x ,double _y ,double _z){
x = _x;
y = _y;
z = _z;
}
public double getDistance(Point point){
result = Math.sqrt(point.x * point.x + point.y * point.y + point.z * point.z);
return result;
}
private double result;
private double x;
private double y;
private double z;
}
|