/* Template for Problem1
 *
 * Students need to supply the bodies of the methods that we indicate in this file 
 * and submit the ENTIRE, completed version.
 * 
 * The following empty methods are known as STUBS, which are
 * method/class headers with no bodies. By working on each method
 * individually, you can develop and test each method to build your
 * program instead of trying to do it all at once.
 */

public class Problem1 {

    // Class variables (visible to all methods in Problem1):
    public static final double EPS = 0.001;     // tolerance
    public static final double MAXITERS = 1000; // max iterations allowed
    public static final double TARGET = 0;      // target value of pile depth equation
    public static double gamma;                 // kN/m^3, unit weight of soil
    public static double phi;                   // 30deg, measure of soil friction
    public static double length;                // m, height of pile above ground cut
    public static double force;                 // kN/m, force that soil exerts on pile, per unit m

    //*********************************************************************
    // Start program: 
    // set param values and then perform both numerical techniques:
    //*********************************************************************
    public static void main(String[] args) {

	welcome();
	setParams();
	process();

    } // Method main

    //*********************************************************************
    // Welcome to user in a cheery fashion:
    //*********************************************************************
    public static void welcome() {

	System.out.println("Welcome to Problem 1 of A4!");

    } // Method welcome


    //*********************************************************************
    // Parameters used by pile depth equation:
    //*********************************************************************
    public static void setParams() {

	gamma  = 18.0;      
	phi    = Math.PI/6;
	length = 3.0;      
	force  = 30;       
	// a better approach would be using file I/O

    } // Method setParams


    //*********************************************************************
    // Prompt user for technique until finished:
    //*********************************************************************
    public static void process() {

	boolean stop = false;
	while (!stop) {
	    System.out.print("Which technique do you want? [(L)HSRHS,(B)isection,(Q)uit]: ");
	    String sol = SavitchIn.readLine();
	    sol = sol.toUpperCase();
	    if (sol.equals("L") || sol.equals("B"))
		solveEqn(sol);
	    else if(sol.equals("Q"))
		stop = true;
	    else
		System.out.println("What?");
	}

	System.out.println("Good-bye!");

    } // Method process

    //*********************************************************************
    // Solve pile depth equation with a particular technique:
    //*********************************************************************
    public static void solveEqn(String s) {

	double depth = -1;  // solution so far
	
	if (s.equals("L")) {
	    s = "LHSRHS";
	    depth = lhsrhs();
	} else if (s.equals("B")) {
	    s = "BISECTION";
	    depth = bisection();
	} else {
	    System.out.println("Fatal error code 13-7. Aborting!"); 
	    System.exit(0); 
	}

	if (depth <= 0)
	    System.out.println("No solution for "+s+" .");
	else {
	    System.out.println(s+": "+depth);
	    System.out.println("EQN: "+evalPileDepthEqn(depth));
	}


    } // Method solveEqn


    //*********************************************************************
    // LHSRHS Method: return the root of the pile depth equation:
    // 
    // COMPLETE THIS METHOD
    //*********************************************************************
    public static double lhsrhs() {

	// delete this statement -- for now, we return a dummy value so 
	// that the program compiles and runs
	return -99999; 
	      
    } // Method lhsrhs

    //*********************************************************************    
    // Return the sign of x...zero values are considered as positive:
    // (convenient helper method for LHSRHS)
    //*********************************************************************
    public static int sign(double x) {
	return x >= 0 ? 1 : -1;
    }

    //*********************************************************************    
    // Bisection Method: return the  root of the pile depth equation:
    //
    // COMPLETE THIS METHOD
    //*********************************************************************
    public static double bisection() {

	// delete this statement -- for now, we return a dummy value so 
	// that the program compiles and runs
	return -99999; 

    } // Method bisection

    //*********************************************************************
    // Return the value of the pile depth equation
    // Requires supplied depth and previously set params
    //
    // COMPLETE THIS METHOD
    //*********************************************************************
    public static double evalPileDepthEqn(double d) {

	// delete this statement -- for now, we return a dummy value so 
	// that the program compiles and runs
	return -1; 

    } // Method evalPileDepthEqn
     
} // Class Problem1
