Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- /*
- Object Class
- */
- public class Point {
- private int x;
- private int y;
- public Point() //default constructor
- {
- x = 0;
- y = 0;
- }
- public Point(int x1, int y1) {
- if (x1 >= 0 || y1 >= 0) {
- x = x1;
- y = y1;
- } else {
- x = 0;
- y = 0;
- }
- }
- public void setX(int x1) //Mutator Method
- {
- x = x1;
- }
- public void setY(int y1) //Mutator method
- {
- y = y1;
- }
- public int getX() //Assesor Method
- {
- return x;
- }
- public int getY() //Assesor method
- {
- return y;
- }
- public double DistanceToOrigin() // nonstaic method that returns values to the main program
- {
- return (Math.sqrt(x * x + y * y));
- }
- public void PrintPoint() // nonstatic method we must make an object reference
- {
- System.out.println(" Point p1 = (" + x + " , " + y + " )");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement