-1

Basically I am trying to make an endPosition take the values from position and add to those x, y values.

I am just struggling to figure out the right syntax to do so.

Point position= new Point((int) (Math.random()*(max - min)), (int) (Math.random() *(max - min)));
Point endPosition = new Point();
Point endPosition = (position.x + 2);
Nowhere Man
  • 19,170
  • 9
  • 17
  • 42

2 Answers2

3

Simply create a new object and pass the required arguments in the constructor.

Point position= new Point((int) (Math.random()*(max - min)),(int) (Math.random() *(max - min)));
Point endPosition = new Point(position.x+2, position.y+3);
donquih0te
  • 597
  • 3
  • 22
  • Thanks, this is what i was originally attempting and it wasnt working so i thought there was something wrong with it. Turns out i was just being really dumb and naming new Point endPosition on 2 seperate lines, confusing the IDE. – Tyler Burke Sep 13 '20 at 17:23
0

So you want to add (int) (Math.random()*(max - min) and (int) (Math.random() *(max - min)

You can create 2 data member in the class say int x and int y and a third data member say int sum

and do the following

class Point{
int x;
int y;
int sum;
Point(int x,int y){
    this.x = x;
    this.y = y;
   }
}

And then in main Simply create an instance of the class.

Point position = new Point((int) (Math.random()*(max - min)),(int) (Math.random() *(max - min)));

position.sum = position.x+position.y;
Swapnil Padaya
  • 687
  • 5
  • 14