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

Drastically need help, this is my third time posting, the first one was never an

ID: 3691656 • Letter: D

Question

Drastically need help, this is my third time posting, the first one was never answered and the second answer was a complete different program, I have attempted this on my own but this is what the programing instructions are:

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 numbers that represent t}Phe (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 two parameters (say, x1 and y1) and should set the x coordinate equal to x1, the y coordinate equal to y1, and the z coordinate to 0.

The main program should declare two objects of type Point in the following manner:

Point A = new Point();

Point B = new Point(1.5, -3.1);

In the main program, prompt the user for new x, y, z coordinates for A and set the data elements of A equal to the user inputs.

The “A” point moves to the right (positive x direction) by 1.5 units, down (negative y direction) by 2.3 units and up in elevation (positive z direction) by 1.5 units. This should be done through a separate method and not via a set() method.

The main program should then determine which point (A or B) is furthest from the origin and print out the (x, y, z) coordinates of the most distant point. (If points 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.

------------------------------------------------------------------------------------------------------------------------------------------

Desired output is :

Enter the coordinates for A
1
1
1
Point furthest from origin has coordinates = (2.5, -1.2999999999999998, 2.5)
The points are 3.23882694814033 apart.

----------------------------------------------------------

I would post my program but it is riddled with error and trying to be more clear on what the program is supposed to do rather than receiving a completely different program that had zero private classes nor any constructor methods. Please help.

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package point1;
import static java.lang.Math.sqrt;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Point1 {

    static class Point {
        private float x ,y, z;
        Point(){
          
        } // end constructor Point
      
        Point(float x1, float y1)   {
            x = x1; y = y1; z = 0;
          
        } // end 2 param constructor
      
        void set(float x1, float y1, float z1) {
            x = x1; y = y1; z = z1;
          
        } // end set function
      
        void move() {
            float x1 = (float) 1.5;
            float y1 = (float) -2.3;
            float z1 = (float) 1.5;
            x = x + x1;
            y += y1;
            z += z1;
        } // end move function
        void findDistance(float x1, Float y1, float z1, float x2, float y2,float z2)    {
            float dist = (float)0.0, dist1FromOrigin = (float)0.0, dist2FromOrigin = (float)0.0;
            //formulat for distance = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2);
            System.out.println("Point A coordinates are: " + x1 + y1 + z1);
            System.out.println("Point B coordinates are: " + x2 + y2 + z2);
           
            dist = (float) sqrt ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1));
            System.out.println("The points are " + (dist) + " apart");
            // distance of point A from Origin
            dist1FromOrigin = (float) sqrt((x1-0)*(x1-0) + (y1-0)*(y1-0) + (z1-0)*(z1-0));
            dist2FromOrigin = (float) sqrt((x2-0)*(x2-0) + (y2-0)*(y2-0) + (z2-0)*(z2-0));
            System.out.println("Distance of point A FROM origin = " + dist1FromOrigin);
            System.out.println("Distance of point B FROM origin = " + dist2FromOrigin);
          
            if (dist2FromOrigin >= dist1FromOrigin) System.out.println("Point furthest from origin has corordibnates = ( " + x2 + " , " + y2 + " , " + z2 + " ) ");
            else System.out.println("Point furthest from origin has corordibnates = ( " + x1 + " , " + y1 + " , " + z1 + " ) ");
              
        } // end findDistance function
    } // end class Point
  
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      
        Point A;
        A = new Point();
        Point B;
        B = new Point((float)1.5, (float)-3.1);
        Scanner sc = new Scanner(System.in);
        float x1, y1,z1;
        float x2=(float)1.5, y2 = (float)-3.1, z2 = (float)0.0;
        System.out.println("Enter the coordinates for A");
        x1 = sc.nextFloat();
        y1 = sc.nextFloat();
        z1 = sc.nextFloat();
        A.set(x1, y1, z1); // initialize the point
        A.move();   // move the point
        A.findDistance(x1, y1, z1, x2, y2, z2);
      
      
    }
  
}

run:
Enter the coordinates for A
1.74
2.65
3.9
Point A coordinates are: 1.742.653.9
Point B coordinates are: 1.5-3.10.0
The points are 6.9519854 apart
Distance of point A FROM origin = 5.025943
Distance of point B FROM origin = 3.443835
Point furthest from origin has corordibnates = ( 1.74 , 2.65 , 3.9 )
BUILD SUCCESSFUL (total time: 9 seconds)

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