You are on page 1of 4

Shayan Zameer

OOP

Lab Object Passing

1. Create an Encapsulated class Point class with x and y as data members. Create two
constructors and a function to move the point.

In the runner create an array of point objects of size 10. Initialize first five objects
using default constructor and others using argument constructor.

Now set the Y coordinate of all default points to 19.

Move objects created with argument constructor by 3 and 4.

Solution code
class point{
private double x;
private double y;

// constructor

public point(){
x = 1.7;
y = 2.5;
}
// argumented
public point (double a, double b){
x= a;
y = b;
}

// setters

void setX(double a){


x = a;

}
void setY(double a){
y = a;

// getters

double getX(){
return x;
}
double getY(){
return y;

void to_move_point(double a, double b){


x = x+a;
y = y+b;

}
void display(){
System.out.println("THE VALUE OF X IS"+ x);
System.out.println("THE VALUE OF Y IS"+ y);
}

}
RUNNER FILE:
public class runnerpoint{
public static void main(String[] args) {

point [] arr= new point[10];

arr[0]=new point();
arr[1]=new point();
arr[2]=new point();
arr[3]=new point();
arr[4]=new point();

for(int i = 0; i<5;i++){
arr[i].setY(19);
}

System.out.println(" \nDisplay1\n");

for(int i = 0; i<5; i++){


arr[i].display();
}
for(int i = 0; i<5;i++){
arr[i].to_move_point(3,4);
}

System.out.println(" \nDisplay2\n");

for(int i = 0; i<5;i++){
arr[i].display();
}

}
}

You might also like