class Point2D {
double x;
double y;
}
public class Main {
public static void main(String[] args) {
Point2D p = new Point2D();
p.x = 10;
p.y = 20;
System.out.println("[" + p.x + ", " + p.y + "]");
}
}
Create a new package called "geometry". Create two classess: Path2D and Point2D.
Point2D should have 2 doubles: x and y. Create a static method, that takes two Point2Ds as argument and returns a distance between them.
Create a static method returning a new random Point2D.
Path2D should store array of Point2D. Create a method, that creates new Path2D. It should take length of path as a argument. Don't put values into array.
Create a static method returning a new random Path2D.
Create a method, that adds new point to path. Look up for empty slot in array (value==null).
Create a static method, that prints all points located in Path2D.
Run following scenario in main method, check if it is working properly.
public class Main {
public static void main(String[] args) {
Path2D path = Path2D.createPath();
Path2D.addPointTo(path);
Path2D.addPointTo(path);
Path2D.addPointTo(path);
Path2D.print(path);
}
}
Create a static method, that sorts points in path. Points should keep minimal distance between them.
Add a static method, that translates each point in path by x and y parameters.
Add a static method, that allows to scale a path (multiply x and y).
Create a static method, that splits path into two. It should return 2-elements array of containing two paths.
Create a static method, that rotates a point by angle. Hint: https://academo.org/demos/rotation-about-point/
Add a variable in Point2D called: index. Modify all methods to keep index of a point in an array inside the point.
Write a scenario in main, that contains two Path2D. Create a new Point2D and put it into two paths. Modify the point using Path2D code (i.e. translate path). Check of values of point in paths. What happend? Why?