I asked this question earlier today, but no one has answered it and it is due in
ID: 3817388 • Letter: I
Question
I asked this question earlier today, but no one has answered it and it is due in a few hours. Please help!!!
3:25 PM 48% MD oo AT&T; KAssign14.docx Assign14.docx Write an error-free Java program to do the following things. Write a class called Point that has only private data members. The data members should be floating point (decimal) numbers that represent the (x, y, z) coordinates of a point. Point should have two constructor functions. The default constructor should place the point at the origin. The second constructor should have three parameters (say, x 1,yl and zl) and should set the x coordinate equal to x1, the y coordinate equal to yl, and the z coordinate to zl. The main program should declare two objects of type Point in the following manner: Point A new Point0: Point B new Point(2. 1.3, 5) In the main program, prompt the user for new x, y, z coordinates for A and set the data elements of Acqual to the user inputs. The "A" point moves to the left (negative x direction) by 1.75 units, down (negative y direction by 2 units and up in elevation (positive z direction) by 3.5 units. This should be done through a separate method and not via a set0 method. The main program should then determine which point (Aor coordinates of the most distant point. (Ifpoints are equidistant, then it does not matter which point coordinates are displayed.) The program should also display how far apart the points are in 3D space. The mathematical calculations should be done via class methods and not done in main. Enter the coordinates for A .Enter the coordinates for A To Do Notifications Messages Courses CalendarExplanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
class Point{
private double x,y,z;
public Point(){
x=0;y=0;z=0;}
public Point(double x1,double y1,double z1){
x=x1;
y=y1;
z=z1;}
void setX(double x1){x=x1;}
void setY(double y1){y=y1;}
void setZ(double z1){z=z1;}
double getX(){return x;}
double getY(){return y;}
double getZ(){return z;}
void moveLeft(double x1){
x= x-x1;}
void moveDown(double y1){
y= y-y1;}
void moveUp(double z1){
z= z+z1;}
double getDistance(double x1,double y1,double z1){
double dx=(x-x1);
double dy=(y-y1);
double dz=(z-z1);
return Math.sqrt(dx*dx+dy*dy+dz*dz);
}
public String toString(){
return "(" + x + ", " + y + ", "+ z +")";
}
public static void main(String[] args) {
Point A = new Point();
Point B = new Point(2.1,-1.3,5);
System.out.println("Enter the coordinates for A");
Scanner sc=new Scanner(System.in);
double x1,y1,z1;
x1=sc.nextDouble();
y1=sc.nextDouble();
z1=sc.nextDouble();
A.setX(x1); //setter values caling methods
A.setY(y1);
A.setZ(z1);
double distanceA=A.getDistance(0,0,0);//get ditnace from orgin and A
double distanceB=B.getDistance(0,0,0);//get ditnace from orgin and B
if(distanceA>distanceB )
System.out.println("Point farthest from origin has coordinates = " + A.toString());
else
System.out.println("Point farthest from origin has coordinates = " + B.toString());
A.moveLeft(1.75);
A.moveDown(2.0);
A.moveUp(3.5);
double distance=B.getDistance(A.getX(),A.getY(),A.getZ());//get distance btw A and B
System.out.println("The points are "+distance+" apart.");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.