Scanner scan = new Scanner(System.in);

System.out.println("Welcome to MathCodeV2.");

int process = 0;

while(process == 0){

System.out.println("Select one of the following:");

System.out.println("\t1: solve for midpoint, distance, dilation or slope using two coordinates.");

System.out.println("\t2: calculate the angles of a regular polygon according to its side count.");

System.out.println("\t3: find the arc length and sector area with angle measure and radius.");

System.out.println("\t4: collective adding; add as many numbers as you want and find their sum and average.");

System.out.println("\t5: find the area of a regular polygon");

System.out.println("\t6: find the area of a regular polygon using apothem and perimeter");

System.out.println("Which operation would you like to execute? (enter 0 to terminate the program)");

int op = scan.nextInt();

if(op == 0){

process = process+1;

}

if(op<0 || op>6){

System.out.println("[Operation \"" +op+ "\" does not exist, try again]");

}

if(op == 1){

int repeat = 0;

System.out.println("YOU'VE SELECTED OPERATION 1. You will enter: (first x, first y) and (second x, second y).

The dilation function will assume the second point to be the pre-image and the first to be the image");

while(repeat == 0){

System.out.print("Enter the first x coordinate:");

double x1 = scan.nextDouble();

System.out.print("Enter the first y coordinate:");

double y1 = scan.nextDouble();

System.out.print("Enter the second x coordinate:");

double x2 = scan.nextDouble();

System.out.print("Enter the second y coordinate:");

double y2 = scan.nextDouble();

double dilationX = x2/x1;

double dilationY = y2/y1;

double slopeX = x2-x1;

double slopeY = y2-y1;

double slope = slopeY/slopeX;

double midpointX = (x1+x2)/2;

double midpointY = (y1+y2)/2;

double distance = Math.sqrt(Math.pow(slopeX, 2)+Math.pow(slopeY, 2));

System.out.println("Your coordinates were (" +x1+ "," +y1+ ") and (" +x2+ "," +y2+ "). Here are the results..." );

System.out.println("\tMidpoint: (" +midpointX+ "," +midpointY+ ")");

System.out.println("\tDistance: " +distance);

if(dilationX == dilationY){

System.out.println("\tDilation: " +dilationX);

}else{

System.out.println("\tDilation: (x" +dilationX+ ",y" +dilationY+ ")");

}

System.out.println("\tSlope: " +slope+ ", or " +slopeY+ "/" +slopeX);

System.out.println("Repeat operation? yes(1), no(2)");

repeat = scan.nextInt();

while(repeat > 2 || repeat < 1){

System.out.println("[Not valid]");

System.out.println("choose yes(1) or no(2)");

repeat = scan.nextInt();

}

if(repeat == 1){

repeat = 0;

}

}

System.out.println();

}

if(op == 2){

int repeat2 = 1;

while(repeat2 == 1){

System.out.println("YOU'VE SELECTED OPERATION 2.");

int process2 = 0;

while(process2 == 0){

System.out.println("How many sides does your polygon have?");

int sides = scan.nextInt();

if(sides<3){

System.out.println("You can't have a polygon with " +sides+ " side(s) you doofus. Try again.");

}else{

process2 = 1;

int degrees = (sides-2)*180;

double angle = degrees/sides;

System.out.println("A regular polygon with " +sides+ " sides...");

System.out.println("\tHas " +degrees+ " degrees total");

System.out.println("\tEach angle has a measure of " +angle+ " degrees");

}

}

System.out.println("Repeat operation? yes(1), no(2)");

repeat2 = scan.nextInt();

while(repeat2<1 || repeat2>2){

System.out.println("[Not valid]");

System.out.println("choose yes(1) or no(2)");

repeat2 = scan.nextInt();

}

}

System.out.println();

}

if(op == 3){

System.out.println("YOU'VE SELECTED OPERATION 3.");

int repeat3 = 1;

while(repeat3 == 1){

System.out.println("Enter the radius of the cirlce: ");

double r = scan.nextDouble();

while(r<0){

System.out.println("You must enter a positive value for radius: ");

r = scan.nextDouble();

}

System.out.println("Enter the angle measure of the arc: ");

double am = scan.nextDouble();

while(am<0){

System.out.println("You must enter a positive value for angle measure: ");

am = scan.nextDouble();

}

double arcL = (am*2*Math.PI*r)/360;

double arcLP = (am*2*r)/360;

double areS = (am*Math.PI*Math.pow(r, 2))/360;

double areSP = (am*Math.pow(r, 2))/360;

System.out.println("In terms without PI...");

System.out.println("\tArc length: " +arcL);

System.out.println("\tSector area: " +areS);

System.out.println("In terms of PI...");

System.out.println("\tArc length: " +arcLP+ " times pi");

System.out.println("\tSector area: " +areSP+ " times pi");

System.out.println("Repeat operation? yes(1), no(2)");

repeat3 = scan.nextInt();

while(repeat3>2 && repeat3<1){

System.out.println("[Not valid]");

System.out.println("choose yes(1) or no(2)");

repeat3 = scan.nextInt();

}

}

System.out.println();

}

if(op == 4){

System.out.println("YOU'VE SELECTED OPERATION 4.");

System.out.println("Collective adding lets you add up all the numbers you want and then finds their average.

This is mainly used for grading and other functions.");

int repeat4 = 1;

while(repeat4 == 1){

double add = 1;

double sum = 0;

int counter = 1;

int cont = 0;

System.out.println("Enter a negative value to stop...");

while(cont == 0){

System.out.print("Num" +counter+ ":");

add = scan.nextDouble();

if(add<0){

add = Math.abs(add);

cont = 1;

}else{

sum = add+sum;

counter = counter+1;

}

}

counter = counter-1;

double ave = sum/counter;

System.out.println("Here are the results...");

System.out.println("You entered " +counter+ " numbers which add up to " +sum);

System.out.println("\tAverage: " +ave);

System.out.println("Repeat operation? yes(1), no(2)");

repeat4 = scan.nextInt();

while(repeat4>2 || repeat4<1){

System.out.println("[Not valid]");

System.out.println("choose yes(1) or no(2)");

repeat4 = scan.nextInt();

}

}

System.out.println();

}

if(op == 5){

System.out.println("YOU'VE SELECTED OPERATION 5.");

int repeat5 = 1;

while(repeat5 == 1){

System.out.println("Find the area of...");

System.out.println("\t1: triangle

\t2: square/rectangle/parallelogram

\t3: trapezoid

\t4: rhombus/kite

\t5: circle");

int op2 = scan.nextInt();

while(op2>5 || op2<1){

System.out.println("[Not valid]");

System.out.println("Choose a valid option:");

op2 = scan.nextInt();

}

if(op2 == 1){

System.out.println("Triangle area = bh/2");

System.out.print("Enter base: ");

double b = scan.nextDouble();

while(b<0){

System.out.println("[No negative values]");

System.out.println("Base must be more than 0:");

b = scan.nextDouble();

}

System.out.print("Enter height: ");

double h = scan.nextDouble();

while(h<0){

System.out.println("[No negative values]");

System.out.println("Height must be more than 0:");

h = scan.nextDouble();

}

double a = (b*h)/2;

System.out.println("Area: " +a);

}

if(op2 == 2){

System.out.println("Square/rectangle/parallelogram area = bxh");

System.out.print("Enter base: ");

double b = scan.nextDouble();

while(b<0){

System.out.println("[No negative values]");

System.out.println("Base must be more than 0:");

b = scan.nextDouble();

}

System.out.print("Enter height: ");

double h = scan.nextDouble();

while(h<0){

System.out.println("[No negative values]");

System.out.println("Height must be more than 0:");

h = scan.nextDouble();

}

double a = b*h;

System.out.println("Area: " +a);

}

if(op2 == 3){

System.out.println("Trapezoid area = (h(b1+b2))/2");

System.out.print("Enter base 1: ");

double b1 = scan.nextDouble();

while(b1<0){

System.out.println("[No negative values]");

System.out.println("base 1 must be more than 0:");

b1 = scan.nextDouble();

}

System.out.print("Enter base 2: ");

double b2 = scan.nextDouble();

while(b2<0){

System.out.println("[No negative values]");

System.out.println("base 2 must be more than 0:");

b2 = scan.nextDouble();

}

System.out.println("Enter height: ");

double h = scan.nextDouble();

while(h<0){

System.out.println("[No negative values]");

System.out.println("height must be more than 0:");

h = scan.nextDouble();

}

double a = (h*(b1+b2))/2;

System.out.println("Area: " +a);

}

if(op2 == 4){

System.out.println("Rhombus/Kite area = (d1xd2)/2");

System.out.print("Enter diagonal 1: ");

double d1 = scan.nextDouble();

while(d1<0){

System.out.println("[No negative values]");

System.out.println("diagonal must be more than 0:");

d1 = scan.nextDouble();

}

System.out.print("Enter diagonal 2: ");

double d2 = scan.nextDouble();

while(d2<0){

System.out.println("[No negative values]");

System.out.println("diagonal must be more than 0:");

d2 = scan.nextDouble();

}

double a = (d1*d2)/2;

System.out.println("Area: " +a);

}

if(op2 == 5){

System.out.println("Circle area = pi(r squared)");

System.out.print("Enter the radius: ");

double r = scan.nextDouble();

while(r<0){

System.out.println("[No negative values]");

System.out.println("radius must be more than 0:");

r = scan.nextDouble();

}

double a = Math.PI*Math.pow(r, 2);

System.out.println("Area: " +a);

}

System.out.println("Repeat operation? yes(1), no(2)");

repeat5 = scan.nextInt();

while(repeat5>2 || repeat5<1){

System.out.println("[Not valid]");

System.out.println("choose yes(1) or no(2)");

repeat5 = scan.nextInt();

}

}

System.out.println();

}

if(op == 6){

int repeat6 = 1;

while(repeat6 == 1){

System.out.print("Enter apothem: ");

double ap = scan.nextDouble();

while(ap<0){

System.out.println("[No negative values]");

System.out.println("apothem must be more than 0:");

ap = scan.nextDouble();

}

System.out.print("Enter perimeter: ");

double p = scan.nextDouble();

while(p<0){

System.out.println("[No negative values]");

System.out.println("perimeter must be more than 0:");

p = scan.nextDouble();

}

double a = (ap*p)/2;

System.out.println("Area: " +a);

System.out.println("Repeat operation? yes(1), no(2)");

repeat6 = scan.nextInt();

while(repeat6>2 || repeat6<1){

System.out.println("[Not valid]");

System.out.println("choose yes(1) or no(2)");

repeat6 = scan.nextInt();

}

}

System.out.println();

}

}

System.out.println("Program terminated. Thank you for using MathCodeV2 by Mr.M");

}