Explain some simple code

New to Java can some explain where i have commented LOST HERE on the code example
MainFile.java
ShapeX.java
ShapeX.java
USA Java NewbieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

quizwedgeCommented:
I think you meant to upload TwoDPoint.java instead of ShapeX.java, but I think I can explain what is going on without that file.

In MainFile.java you have the following two lines commented with "LOST HERE":
TwoDPoint p = new TwoDPoint(x,y);
s.addPoint(p);	

Open in new window

The first line is taking the two integers you entered for x and y and creating a new TwoDPoint object. The second line then passes it to the addPoint method of the ShapeX object.

This takes us to your other "LOST HERE" section of code. This time in ShapeX.java:
public void addPoint(TwoDPoint p)
{ points.add(p); }	

Open in new window

Further up in the file, on line 6 you'll see that you have a private variable named points. It is an ArrayList with objects of type TwoDPoint. The lines of code in ShapeX.java are a function which has one line of code which adds a new twoDPoint object to the ArrayList.

For example, let's assume that you entered 3 and 4 for your x and y points. In MainFile.java that would create a new TwoDPoint object (p) with points 3 and 4. That object (p) gets passed to the addPoint function in ShapeX.java which adds the object with points 3 and 4 to the ArrayList named points in ShapeX.java.
0
USA Java NewbieAuthor Commented:
Sorry you right file attached
0
quizwedgeCommented:
Sorry, I'm still not seeing the file. Did my answer help? I may not need to see the file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.