Help with Java problem

Hello there,

So, I’m pretty new to coding and recently started doing a computer science internship specifically for high school students like myself. I haven’t been doing much at my internship lately, but today the teacher who is in charge of this internship told me that he wanted me to start implementing algorithms, which isn’t something I have a lot of experience with. I would appreciate if anyone was willing to give me some pointers and some guidance.

Basically, we are working with robotics and using Java. What he wants me to do is use Math.random to create a bunch of points on a 2 dimensional plane. These points will go into an array, and divided between x coordinated and y coordinates. Then, a for loop will run, and these points will move. These new points will be put into a new array, and this will continue on and on until all the points get to a certain spot, and they will all stop running.

All that he has asked me to do is to create the initial for loop that will run the math.random function, put these numbers into an array, and then run it again to create a new array. It also needs to calculate the total distance from each points, so it will take say point 1, it will be all the distances added up and then divided by n (he said to start with 50 points).

I am learning for loops, arrays, while loops, and all of the above, but I just don’t have a lot of experience with it. I was wondering if I could just get some guidance. It will all be very much appreciated.

Thank you!

otherwise known as a coordinate plane in two axes. Are you familiar with trigonometry? The distance formula?

Yes, I am. 2 dimensional plane is simply the term that he used to describe it.

What is the expected domain and range? How many points are there supposed to be? What is the f(x)?

There isn’t anything there that’s obviously going to trip you up - one foot in front of the other? Pick one small part of those actions, implement it, continue with the next.
Whenever something is difficult, try to identify what stops you from continuing, drop everything else and work on obtaining that knowledge and then keep going.

We are working on a 100 x 100 plane. As state above, he said to start with 50 points, but in the end, it will be running on n points, and the value of n will be imputed. In order to find the sum, we are going to be using summation to find the overall distance from point x to point n. All the points locations will be subtracted from the first point, the absolute values will be added up, and then divided by n, which in this case if defined as 50. This will be continued for each point.

Thank you for the advice. Do you have any recommended resources for learning more about coding arrays and loops?

Google the things you want to do. Somebody will have asked, somebody will have replied, somebody will have written a tutorial, and google will have been there.
This site shows how to do a bunch of common operations: https://learnxinyminutes.com/docs/java/

1 Like

Thank you. I will check out that website. I appreciate it.