Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3:25 PM 48% MD oo AT&T; KAssign14.docx Assign14.docx Write an error-free Java pr

ID: 3817168 • Letter: 3

Question

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. TISIEnter the coordinates for A .Enter the coordinates for A Courses Calendar To Do Notifications Messages

Explanation / Answer

Hi,

Please see below the classes .Please comment for any queries/feedbacks.

Thanks,

Anita

Point.java

import java.util.Scanner;


public class Point {
   private double x;
   private double y;
   private double z;
  
  
   //NoArg Constructor
   public Point(){
       this.x = 0;
       this.y = 0;
       this.z = 0;
   }

   //Parameterized Constructor
   public Point(double x1, double y1, double z1) {
       this.x = x1;
       this.y = y1;
       this.z = z1;
   }
  
  
   //Method to move this point
   public void move(double x1, double y1, double z1){
       this.x = this.x + x1;
       this.y = this.y + y1;
       this.z = this.z + z1;
   }
  
  
   //Method to find the nearest Point form origin. Origin coordinates are (0,0,0)
   public static Point getNearestPoint(Point A,Point B){
       Point retPoint= null;
       double xo = 0; //Origin coordinates
       double yo = 0; //Origin coordinates
       double zo = 0; //Origin coordinates
       double x1 = A.getX();
       double y1 = A.getY();
       double z1 = A.getZ();
       double x2 = B.getX();
       double y2 = B.getY();
       double z2 = B.getZ();
       double distance = 0.0;
       //Calculating the distance from origin
       double distance1 = Math.sqrt(((xo-x1)*(xo-x1)) + ((yo-y1)*(yo-y1)) + ((zo-z1)*(yo-z1)));
       double distance2 = Math.sqrt(((xo-x2)*(xo-x2)) + ((yo-y2)*(yo-y2)) + ((zo-z2)*(yo-z2)));
       if(distance1>distance2){
           distance = distance1 -distance2; //Distance between A and B
           retPoint = A;
       }
       else{
           distance = distance2 -distance1; //Distance between A and B
           retPoint = B;
       }
       System.out.println("Point furthest from origin has coordinates = ("+retPoint.getX()+","+retPoint.getY()+","+retPoint.getZ()+")");
       System.out.println("The points are "+distance+ " apart.. ");
      
       return retPoint;
   }

  
   //Getters and Setters
   public double getX() {
       return x;
   }

   public void setX(double x) {
       this.x = x;
   }

   public double getY() {
       return y;
   }

   public void setY(double y) {
       this.y = y;
   }

   public double getZ() {
       return z;
   }

   public void setZ(double z) {
       this.z = z;
   }

  
   //Main method
   public static void main(String [] args){
       Scanner scan = new Scanner(System.in);
       Point A= new Point();
       Point B= new Point(2.1,-1.3,5);
      
       //reading the cocordinates from user
       System.out.println("Please enter the coordinates");
       System.out.println("x :");
       String x = scan.nextLine();
       System.out.println("y :");
       String y = scan.nextLine();
       System.out.println("z :");
       String z = scan.nextLine();
      
       //Setting the user entered coordinates to A
       A.setX(Double.valueOf(x));
       A.setY(Double.valueOf(y));
       A.setZ(Double.valueOf(z));
      
      
       //Moving A,as specified
       A.move(-1.75, -2, 3.5);
      
       //Getting the nearest point from origin
       getNearestPoint(A,B);
      
   }
  
}

Sample output:

Please enter the coordinates
x :
3.0
y :
1.0
z :
1.0
Point furthest from origin has coordinates = (2.1,-1.3,5.0)
The points are 0.800494103803775 apart..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote