line.java

import java.io.*; // for I/O
////////////////////////////////////////////////////////////////
class Points
{
private int xx;
private int yy;
public Points(int va1, int va2)
{
xx = va1;
yy = va2;
}
public int getX()
{
return xx;
}
public int getY()
{
return yy;
}
public void display()
{
System.out.println("x:"+xx+"  y:"+yy);
}
}
class lineCal
{
private Points point1;
private Points point2;
public lineCal(Points obj1,Points obj2)
{
point1 = new Points(obj1.getX(),obj1.getY());
point2 = new Points(obj2.getX(),obj2.getY());
}
public double lengthCal()
{
double subx = point1.getX() - point2.getX();
double suby = point1.getY() - point2.getY();
double length12 = (double)Math.sqrt(subx*subx + suby*suby);
return length12;
}
}
class maxNum
{
double arr[];
int maxSize;
public maxNum(int max)
{
arr = new double[max];
maxSize = 0;
}
public void push(double item)
{
arr[maxSize]= item;
maxSize++;
}
public double findMax()
{
double max = arr[0];
for(int i=1;i
{
 if(max<arr[i])
max = arr[i];
}
return max;
}
}
class line
{
public static void main(String[] args)
{
Points point1 = new Points(1,2); // initiate a point.
Points point2 = new Points(6,8); // initiate a point.
Points point3 = new Points(56,23); // initiate a point
point1.display();
point2.display();
point3.display();
lineCal line12 = new lineCal(point1,point2);
lineCal line23 = new lineCal(point2,point3);
lineCal line31 = new lineCal(point3,point1);
double va12 = line12.lengthCal();
double va23 = line23.lengthCal();
double va31 = line31.lengthCal();
maxNum maxFind = new maxNum(5);
maxFind.push(va12);
maxFind.push(va23);
maxFind.push(va31);
System.out.println("\nThe biggest length of the lines is: "+maxFind.findMax());
}
}

Output[1]

Happy lining 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s