For these problems you will be working alone.
Clone this repository and on in BlueJ, Visual Studio Code, or your favorite IDE
You will need to create a class named Point that will represent 2D cartesian coordinates
Do the following:
- Create a class called
Point
- Add private instance variables to your Point class called
x
andy
of typedouble
- Create a parameterized constructor that takes x and y
- Create a no-arg constructor
- x and y should be encapsulated. Create accessor (get) and mutator (set) methods for x and y
- Override the
toString
method so that it returns a string in the format of(x, y)
, where x, and y are the instance values for the point. The signature of toString ispublic String toString()
- Override the
equals
method so that it compares the x and y values with those of another point. The signature of equals is:public boolean equals(Object obj)
Do the following:
- Create a class called
PointCheck
- Create a main method. You should be able to rattle the signature off in your sleep by now, but just in case:
public static void main(String[] args)
- In your main method, create 3 instances of your point class with the following values:
- x = 2, y = 4
- x = 2, y = 4 // yes the same value
- x = 4, y = 2
- Also in your main method use reference checking and equality checking to compare point #1 with points #2 and #3. You should print out the result of each in a user-friendly manner.
- Run
PointCheck
. If you're using maven usemvn exec:java "-D.exec.mainClass=PointCheck"
Do the following:
- Create a class called
PointMover
- Create a main method.
- Inside the main method create an array to hold 20 Points.
- Write a for loop to fill the array of points where
x
starts at 20 and goes to 39,y
should start at 39 and go to 20. e.g. #1 is (20, 39), #2 is (21, 38), #3 is (22, 37) ... #20 is (39, 20) - Write a for loop to changes the y value of every other point in the array to 10.5. For example, the first point in the array will be unchanged. The second point will become (21, 10.5). The third point will be unchanged. The forth point will be (23, 10.5), etc.
- Write a for loop that interates over the array of points and prints out any point with an x value between 25 and 30. Make sure you are using the points toString method when printing.
- At the end of your main method, print out the 6th point in your array using the points toString method.
Do the following:
- Create a class called
PointGC
- Create a main method.
- Inside the main method create 2 variables that point at 2 different point instances
- Create an alias variable to one of your points.
- Now add code that can cause one of your point instances to be garbage collected.