//++++ Paste your own code from the z-classes project, then make the indicated changes.
import java.util.*;
class Main {
  static String author=  "Justin Behrman";
  static String title=  "CST 112 [day] Final project:  Tri & Quad classes";
  public static Scanner in=  new Scanner( System.in );

  public static void main(String[ ] args) {
	
	System.out.println(author);    
	System.out.println(title);
	    
	while (true) {    
		
		System.out.println("\n");
		
	    double a, b, c;
	    double[] x = new double[3];		// Array for a,b,c values.
	    
	    double [][] p = new double[3][3];
	    
		System.out.println("Remember, if you would like to exit, then just enter a '0' for any value!");
	    System.out.print( "Enter three values for a, b, c.  ");
	    a=  in.nextDouble();
	    b=  in.nextDouble();
	    c=  in.nextDouble();
	    
	    if (a == 0 || b == 0 || c == 0) {
	    	System.out.println("Have a good one!");
	    	break;
	    }
	    
	    System.out.printf( "Thank you for your input:  %f %f %f\n\n", a, b, c );
	    
		// Create a triangle, a quadratic, and an array, 
		//	using the SAME a, b, c values.
		Tri t=  new Tri( a, b, c );
		Quad q=  new Quad( a, b, c );
		
		// Check the triangle.
		checkTriangle( t );
		
		// Check the quadratic.
		checkQuad( q );
		
		//+++++ ADD CODE TO STORE VALUES IN ARRAY x[].
		
		//System.out.println( "\n//+++++ ADD YOUR OWN CODE TO FILL THE ARRAY AND COMPUTE mu"); 
		
			//+++++ ADD YOUR OWN CODE HERE.
		x[0] = a;
		x[1] = b;
		x[2] = c;
		
		//TASK 1
		
		//Sets the values to be the (i + 1) power. Ends up being 1, 2 and 3 
		for (int i = 0; i < p.length; i++) {
			for (int j = 0; j < p[i].length; j++) {
				
				p[j][i] = Math.pow(x[j], (i + 1));
				
			}
		}
		
		showMultiArray(p);
		
		System.out.println("");
		
		//TASK 2
		Box bubbles = new Box(a, b, c);
		
		System.out.println("The volume of a box with these size is " + bubbles.volume());
	    
	    System.out.println("The surface area for this box is " + bubbles.surface());
		
		System.out.println("\n");
		
		//TASK 3
		
		System.out.println("C is now forced to be the hypotenuse");
		
		t.setC(Math.sqrt(Math.pow(t.getA(), 2) + Math.pow(t.getB(), 2)));
		
		System.out.println(t.getA() + " is a");
		
		System.out.println(t.getB() + " is b");
		
		System.out.println(t.getC() + " is c");
		
		if (t.right()) {
			System.out.println("This is a right triangle after c has been forced to be the hypotenuse");
		} else {
			System.out.println("This is not a right triangle! Wait, how did this happen??"); //This should never be invoked unless round off error. Possible with 3 6 5
		}
		System.out.println("\n");
		//TASK 4
		q.tripleB();
		
		System.out.println("The tripleB() method is now invoked");
		
		checkQuad(q);
		
		q.switchAC();
		
		System.out.println("\nThe switchAC() method is now invoked");
		
		checkQuad(q);
		
		//TASK 5 BELOW
		
		// Display the values in array d[].
		showArray( x, 3 );
	
		double mu=0;	
		//+++++  Calculate "mu" = the mean of the values in d[]; display mu.
		
		for (int i = 0; i < x.length; i++) {
			mu += x[i];
		}
		mu /= x.length;
		System.out.println( "The arithmetic mean is:  " + mu ); 
		System.out.println("The median is " + x[1]);
		//TASK 5 HERE
		for (int i = 0; i < x.length; i++) {
			startCounter((int)x[i]); 
		}
	}
  }//END OF main() //
  
  
  static void checkTriangle( Tri t ) {
	// Check the triangle.
	//	- Is it a valid triangle?
	// 	- If so, what is the perimeter?
	// 	- Is it a right triangle?
	//+++ ADD YOUR OWN METHODS TO ACCESS a, b, and c.
	
		//System.out.println( "//+++++ ADD YOUR OWN CODE FOR TRIANGLE. "); 
	
		//+++++ YOU MAY USE OR DISCARD THESE OUTPUT STATEMENTS.
		
		if (t.valid()) {
		
			System.out.println( "This a triangle!" ); 
			
			System.out.println("The permeter of this triangle is " + t.perimeter());
			
			if (t.right()) {
				System.out.println( "This is a right triangle!" );

			} else {
				System.out.println( "NOT a right triangle!" );
			}
			
		} else {
			System.out.println( "NOT a valid triangle!" ); 
		}
		
  }
	
  //// Check the quadratic:
  static void checkQuad( Quad q ) {
	
	q.show();					// Display the quadratic.
	//q.formula();				// Display quadratic formula.
	double root1=0, root2=0;

	int dis = q.numRoots();
	//System.out.println( "//+++++ ADD YOUR OWN CODE FOR QUADRATIC. "); 
	
	//// Check the quadratic:
	// 	- Does it have two real roots?
	//	- One real root?
	//	- No real roots.
	// Print the root(s), if any.
	
		//+++++ ADD YOUR OWN CODE HERE.
		//System.out.println( "//+++++ REPLACE WITH YOUR OWN CODE TO SHOW ROOTS. "); 
	
	root1 = q.root1();
	root2 = q.root2();
	
	switch (dis) {
		case 0:
			System.out.println( "NO real roots!" ); 
			q.formula();
			break;
		case 1:
			System.out.println( "One real root:  " + root1 );
			break;
		case 2:
			System.out.println( "Two real roots:  " + root1 + ", " + root2 );
			break;
	}
	
		//+++++ YOU MAY USE OR DISCARD THESE OUTPUT STATEMENTS.	
		
  }
  //// Show the values in an array.
  static void showArray( double d[], int m ) {
		System.out.print( "\nValues in the array:  " ); 
		
		Arrays.sort(d);
		//+++++ ADD YOUR OWN CODE HERE.
		//System.out.println( "//+++++ WRITE YOUR OWN CODE TO PRINT THE ARRAY. "); 
  		
  		for (double c: d) {
  			System.out.print(c + " ");
  		}
  	
  }
  
  static void showMultiArray(double p[][]) {
  	
  	for (int i = 0; i < p.length; i++) {
  		for (int j = 0; j < p[i].length; j++) {
  			
  			System.out.print(p[i][j] + " ");
  			
  		}
  		
  		System.out.println();
  		
  	}
  	
  }

  
  //Didn't know where to paste your code, so I just put it in here.
  public static void startCounter(int a) {
  	
    int n= a;
    System.out.printf( "For 1 to %d, the sums are:  %d  %d \n", 
    	n, countUp( n ), countDown( n ) );
    // Now, do the same for b and c.
  	
  }
  
  // Use a loop to compute the sum from 1 to n.
  static int countUp( int n ) {
	int result=0;
	for (int i=0; i<=n; ++i ) {
		
		result += i;
		
	}
  	return result;
  }
  // Recursive method -- no loops allowed!
  static int countDown( int n ) {
		
	int result = 0;
	
	if (n == 1) { return 1; }
	
	result = n + (countDown(n - 1));
		
	return result;
  }
  
}



/** Tri class for triangle. */
class Tri {
	private double a=0, b=0, c=0;
	// CONSTRUCTOR //
	
	Tri() {
		this(1, 1, 1); //Defaults as a equilateral triangle with a height of 1.
	}
	
	Tri( double a, double b, double c ) {
		this.a = a;
		this.b = b;
		this.c = c;
	}

	//// METHODS ////
	// Perimeter.
	double perimeter() { return a+b+c; }
	
	public double getA() {
		return this.a;
	}
	
	public double getB() {
		return this.b;
	}
	
	public double getC() {
		return this.c;
	}
	
	public void setC(double c) {
		this.c = c;
	}
 	
	// Return false if this cannot be a triangle.
	//	No side can be longer than the sum of the other two sides.
	boolean valid( ) {
		
		if (this.a + this.b > this.c && this.a + this.c > this.b && this.c + this.b > this.a) {
			return true;
		}
		return false;
	}

	// Return true if this is a RIGHT triangle:
	// 	The square of the largest side is equal to 
	//	the sum of the squares of the other two sides.
	boolean right( ) {
		
		if (Math.pow(a, 2) + Math.pow(b, 2) == Math.pow(c, 2)) {
			return true;
		}
		return false;
	}
	
}


/** Quad class for quadratic. */
class Quad {
	private double a, b, c;
	private double discrim;
	
	Quad() {
		this(1, 1, 1); //Defaults a, b, and c to be one
	}
	
	// CONSTRUCTOR //
	Quad( double a, double b, double c ) {
		this.a=  a;
		this.b=  b;
		this.c=  c;
		setDiscrim();
	}
	
	//// METHODS ////
	public double getDiscrim() { return discrim; }

	//+++ ADD YOUR OWN METHODS TO ACCESS a, b, c.

	//+++ ADD YOUR OWN METHOD TO MODIFY c.
	
	public void setDiscrim() { discrim=  b*b - 4*a*c; }
	
	public double getA() {
		return this.a;
	}
	
	public double getB() {
		return this.b;
	}
	
	public double getC() {
		return this.c;
	}
	
	// Return roots.
	public double root1() {
		return (((-b) + Math.sqrt(discrim)) / (2 * a));	//+++ REPLACE THIS STATEMENT WITH YOUR OWN CODE!
	}
	public double root2() {
		return (((-b) - Math.sqrt(discrim)) / (2 * a));	//+++ REPLACE THIS STATEMENT WITH YOUR OWN CODE!
	}
	
	public int numRoots() {
		if (discrim > 0) {
			return 2;
		} else if (discrim < 0) {
			return 0;
		} else {
			return 1;
		}
		
	}
	
	public void tripleB() {
		this.b *= 3;
		setDiscrim();
	}
	
	public void switchAC() {
		double temp = this.a;
		this.a = this.c;
		this.c = temp;
		setDiscrim();
	}
	
	/***** NO CHANGES ARE NEEDED BELOW THIS LINE *****/
	/** Methods to display equation & formula. **/
	public void show() { 
		System.out.printf( "\n	%f x\u00b2 + %f x  +  %f\n", a, b, c );
	}
	public void formula() {
		double real=  (-b) / (2*a);
		double imag=  (Math.sqrt(-discrim) ) / (2*a);
		System.out.printf( "	%f \u00b1 %f i\n", real, imag );
	}

	
}

class Box {
	
	private double a, b, c;
	
	Box(double a, double b, double c) {
		this.a = a;
		this.b = b;
		this.c = c;
	}
	
	public double volume() {
		return this.a * this.b * this.c;
	}
	
	public double surface() {
		return (2 * this.a * this.b) + (2 * this.b * this.c) + (2 * this.a * this.c);
	}
	
	
}
