A point on the two-dimensional plane can be represented by two numbers: a X coordinate and a Y coordinate.
import java.util.Scanner;
class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
/**
* @return the x
*/
public int getX() {
return x;
}
/**
* @param x the x to set
*/
public void setX(int x) {
this.x = x;
}
/**
* @return the y
*/
public int getY() {
return y;
}
/**
* @param y the y to set
*/
public void setY(int y) {
this.y = y;
}
};
public class App {
/**
* The start point of the program
*
* @param args
*
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.print("Enter x: ");
int x = keyBoard.nextInt();
System.out.print("Enter y: ");
int y = keyBoard.nextInt();
Point p1 = new Point(x, y);
System.out.println("\nX = " + p1.getX());
System.out.println("Y = " + p1.getY());
keyBoard.close();
}
}
Comments
Leave a comment