Thanks Jeanne, Rob and Vilmantas.
Yes, I need to create something like a point class. And the order of the elements in each of the points is also important. Let me post the actual problem and the solution I came up with. But it is not complete because It still fails with respect to the order. i.e. The points {10,50} and {50,10} are treated same in my code, which is wrong.
Problem :
===================
Shape A defined by a set of (x,y) points in the cartesian xy - plane.
Shape B defined by a set of (x,y) points in the cartesian xy -plane which creates a hollow hole inside of shape A.
Shape C defined by a set of (x,y) points in the cartesian xy-plane.
Write a JAVA console or windows program to find Shape E. E is the intersection of shape C with shape A where A has a hole shape B.
E is a set of (x,y) points in the cartesian xy - plane.
Input of program:
Input for A e.g. (Ax1,Ay1), (Ax2,Ay2), (Ax3,Ay3)�
Input for B e.g. (Bx1,By1), (Bx2,By2), (Bx3,By3)�
Input for C e.g. (Cx1,Cy1), (Cx2,Cy2), (Cx3,Cy3)�
Ouput of program :
Output for E e.g. (Ex1,Ey1), (Ex2,Ey2), (Ex3,Ey3)�
Please provide all code.
===================================
Solution code , which I am still working on. Also bear with me for the mistakes. Please feel free to correct it.
=====================================
import java.util.ArrayList;
public class programone
{
String Shape;
ArrayList<Integer> shapeA = new ArrayList<Integer>();
ArrayList<Integer> shapeB = new ArrayList<Integer>();
ArrayList<Integer> shapeC = new ArrayList<Integer>();
int arrayA[][] = {{100,50},{300,500}, {25, 45},{0,0}};
int arrayB[][] = {{100,50}};
int arrayC[][] = {{40,40},{100,50},{300,500}, {50, 100}, {0,0}};
int k=0;
int l=0;
int m=0;
public static void main(String args[]){
programone p1 = new programone();
p1.logic();
}
public void logic(){
for (int i = 0 ; i < arrayA.length ;i ++ )
{
for (int j =0 ; j <2 ; j ++,k++)
{
shapeA.add(k,arrayA[i][j]);
}
}
for (int i = 0 ; i < arrayB.length ;i ++ )
{
for (int j =0 ; j <2 ; j ++,l++)
{
shapeB.add(l,arrayB[i][j]);
}
}
for (int i = 0 ; i < arrayC.length ;i ++ )
{
for (int j =0 ; j <2 ; j ++,m++)
{
shapeC.add(m,arrayC[i][j]);
}
}
shapeA.removeAll(shapeB);
shapeC.retainAll(shapeA);
System.out.println("ShapeC has a resultant set : " + "{");
for (int y=0; y < shapeC.size(); y ++ )
{
if (y % 2 ==0)
{
System.out.println("{" + shapeC.get(y)
+","+ shapeC.get(y +1)+"}," );
}
}
System.out.println("}");
}
}