Quick Index
A "Point" is a valuable object type for many systems (graphics, engineering, mapping, etc). It's simple yet powerful.

This challenge is to code a basic Point class.

This challenge closely follows the example.
We previously looked at the structure for a class Point.

Note the similarities with the example (Rectangle). Each class has two ivars of type "int".

Add a class "Point" in a file named "Point.java". Type in the code that is shown here.
public class Point {

	private int x;
	private int y;

}
Do not add any constructor methods (like example shown here). We'll learn more about these later.

If you don't yet know what a constructor is, that is fine.
public Point(int x, int y) {
	this.x = x;
	this.y = y;
}

Code Simple Method


Add a method named "moveToOrigin" to the "Point" class.

You can pattern the method header after the method "setSmall" in the example (change name to "moveToOrigin").

The method should do the following:


"set x to 0" means assign the value of 0 to the instance variable "x". (similar to how we assigned a value to "width" in the example).

Another Simple Method


Code another method named "move1".

This method is similar to "moveToOrigin" except that in this case "x" should be set to 100 and "y" should be set to 70.

Code Method That Returns Value


Code a method named "getX".

You can pattern the method header after the method "getWidth" in the example (change name to "getX").

The method should return the ivar "x".

This method "getX" is very similar to "getWidth" from the example, except that we return "x" rather than "width"

Another Method That Returns Value


Code a method named "getY".

This method is similar to "getX" except that this method should return the ivar "y".

Verify Compile


As mentioned at the top it is helpful to compile often.

When done, save the file, and again compile the file and fix any compile errors that are shown (line numbers are indicated).

Note: this file does not need to be run. We'll learn how to run (and test) Point in the next chapter.

Grading


For this assignment, we will use these grading rules.

References