import java.text.NumberFormat; public class LinearCalc { public LinearCalc(double X1, double Y1, double X2, double Y2) { x1 = X1; y1 = Y1; x2 = X2; y2 = Y2; } public LinearCalc(LinearCalc P) { x1 = P.x1; y1 = P.y1; x2 = P.x2; y2 = P.y2; } public double getSlope() { double m = (y2 - y1)/(x2 - x1); return m; } public double getLength() { double l = Math.sqrt(Math.pow(x2 - x1,2) + Math.pow(y2 - y1,2)); return l; } public double getArea() { double a = Math.abs(x2 - x1) * Math.abs(y2 - y1); return a; } public double getPerimeter() { double p = 2 * Math.abs(x2 - x1) + 2 * Math.abs(y2 - y1); return p; } public double getMidX() { double midX = (x2 - x1)/2; return midX; } public double getMidY() { double midY = (y2 - y1)/2; return midY; } public double getCircleArea() { double radius = getLength()/2; double ca = Math.PI * Math.pow(radius,2); return ca; } public double getCircumference() { double diameter = getLength(); double cir = Math.PI * diameter; return cir; } public void Display() { formatter.setMaximumFractionDigits(2); formatter.setMinimumFractionDigits(2); System.out.println("x1, y1 : (" + formatter.format(x1) + "," + formatter.format(y1) + ")"); System.out.println("x2, y2 : (" + formatter.format(x2) + "," + formatter.format(y2) + ")"); System.out.println(); System.out.println("Slope : " + formatter.format(getSlope())); System.out.println("Length : " + formatter.format(getLength())); System.out.println("MidX pt : " + formatter.format(getMidX())); System.out.println("MidY pt : " + formatter.format(getMidY())); System.out.println("Area : " + formatter.format(getArea())); System.out.println("Perimeter: " + formatter.format(getPerimeter())); System.out.println(); System.out.println("Cir Area : " + formatter.format(getCircleArea())); System.out.println("Cir Circ : " + formatter.format(getCircumference())); } private double x1; private double y1; private double x2; private double y2; NumberFormat formatter = NumberFormat.getNumberInstance(); }