import java.text.NumberFormat; public class prgm1 { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); String exit = "Y"; int i = 1; while(exit.equalsIgnoreCase("Y")) { System.out.print("X1 Value: "); double x1value = console.readDouble(); System.out.print("Y1 Value: "); double y1value = console.readDouble(); System.out.print("X2 Value: "); double x2value = console.readDouble(); System.out.print("Y2 Value: "); double y2value = console.readDouble(); LinearCalc one = new LinearCalc(x1value, y1value, x2value, y2value); one.getSlope(); one.getLength(); one.getMidX(); one.getMidY(); one.getArea(); one.getPerimeter(); one.getCircleArea(); one.getCircumference(); System.out.println("------------------------------------------"); System.out.println("Data Set " + i ); System.out.println("------------------------------------------"); one.Display(); System.out.println(); System.out.print("Do you want to Continue [Y/y|N/n]: "); ConsoleReader cont = new ConsoleReader(System.in); String strexit = cont.readLine(); exit = strexit; i++; } } } 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(4); formatter.setMinimumFractionDigits(4); 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(); }