Drastically need help with this program please. Here is the desired output and b
ID: 3691521 • Letter: D
Question
Drastically need help with this program please. Here is the desired output and below that is my sad attempt to program it.
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.
-----------------------------------------------------------------------------------------------------
import java.util.Scanner;
package Point;
public class Point
{
int x = 0,int y = 0, int z = 0; //floating point numbers?
private PointOne //only private data members, two constructor functions
{point = origin};//not sure how to set origin
private PointTwo
{x=x1
y=y1
z=0};
}
public static void main (String arg[])
{
Point PointA = new Point();
Point PointB = new Point(1.5,-3.1);
Scanner in = new Scanner(System.in);
//set new x,y,z coordinates for A
System.out.println("enter x value for A");
PointA.x = in.nextInt();
System.out.println("enter y value for A");
PointA.y = in.nextInt();
System.out.println("enter z value for A");
PointA.z = in.nextInt();
PointA.x = x+1.5
PointA.y= y-2.3
PointA.z= z+1.5 //moving user inputs
if PointA.distance > PointB.distance
{System.out.println("Point furthest from origin has coordinates = "+PointA(x,y,z))};
else {System.out.println("Point furthest from origin has coordinates = "+PointB(x,y,z))};
}
//program should display how far apart points are in 3D space via class method. not sure how to go about that in a class method.
Explanation / Answer
Here im appending a code.Take a look on it,may be it will helps you to over come your problem
import java.util.Random;
public class main
{
static int distance(int x1,int x2)
{
return Math.round((x2-x1)*(x2-x1)); //Math.sqrt is the square root of the 2 coordinates
}
public static void main(String[] args)
{
Random randomGenerator=new Random();
int x2,x1; //The points
int distance; //the Math to work distance
int randomInt2=randomGenerator.nextInt(10)+1; //for length of array
int[] distance=new int[randomInt2]; //the array
int store;
x1=0; //used to calculate distance from original point to current point
System.out.println("distance generation from point1 : 0"); //for first point
int origin=1;//increment which point start from
int range=0; //amount of points
int point=2; //counts the number of points
while(range<randomInt2)
{
int randomInt3=randomGenerator.nextInt(10)+2; //distance for all points besides first
x2=randomInt3;
distance=distance(x1,x2);
System.out.println("the distance between point 1 and point"+point+"is"+distance+".");
System.out.println("distance from point "+origin+"to point"+point+"is distance="+distance);
store=distance; //stores the distance to be put into array
point++; //increments the point number each time
distance[range]=store;
System.out.println("from point"+point+"topoint"+origin+"="+distance);
origin++; //increments origin point
range++; //increments amount of points each time
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.