import java.util.Scanner;
public class MamasFunctionDemoDriver {
    public static void main(String[] args) {
        System.out.println("=== Welcome to Mama's Little Function App! ===\n");
        Scanner kb = new Scanner(System.in);
         
        String xStr = "";
        String prompt = "Enter a real value for x (or type 'q' to quit): ";
        double x = 0.0;
        do{
            System.out.print(prompt);           
            xStr = kb.nextLine();
            if(!xStr.equals("q")) {
                try {
                    x = Double.parseDouble(xStr);
                    double y = f(x);
                    System.out.print("f(" + x + ") = " + y + " ==> ");
                    orderedPair(x, y);
                } catch (NumberFormatException e) {
                    System.out.println("Invalid input. Please enter a valid real number or 'q' to quit.");
                }
            }
            System.out.println(); // Print a blank line for better readability
        }while(!xStr.equals("q")); 
        kb.close();
        System.out.println("Thank you for using Mama's Little Function App! Goodbye!");
    }//end main method

    public static double f(double x) {
        // This is a 'return' type of method: it sends back a result to the calling method (main)
        System.out.println("Calculating f(" + x +")...");
        // Add demonstration code here
        double m = 3.0; // slope
        double b = 2.0; // y-intercept
        return m * x + b;
    }//end method f

    public static void orderedPair(double x, double y) {
        // This is a 'void' type of method: it does not send back a result to the calling method (main)
        // It just performs an action (in this case, printing the ordered pair)
        System.out.println("(" + x + ", " + y + ")");
    }//end method orderedPair  
    
    // Sample Output:
    /*
    === Welcome to Mama's Little Function App! ===

    Enter a real value for x (or type 'q' to quit): 2
    Calculating f(2.0)...
    f(2.0) = 8.0 ==> (2.0, 8.0)

    Enter a real value for x (or type 'q' to quit): -4
    Calculating f(-4.0)...
    f(-4.0) = -10.0 ==> (-4.0, -10.0)

    Enter a real value for x (or type 'q' to quit): 3.9
    Calculating f(3.9)...
    f(3.9) = 13.7 ==> (3.9, 13.7)

    Enter a real value for x (or type 'q' to quit): eight
    Invalid input. Please enter a valid real number or 'q' to quit.

    Enter a real value for x (or type 'q' to quit): 8
    Calculating f(8.0)...
    f(8.0) = 26.0 ==> (8.0, 26.0)

    Enter a real value for x (or type 'q' to quit): Q
    Invalid input. Please enter a valid real number or 'q' to quit.

    Enter a real value for x (or type 'q' to quit): q

    Thank you for using Mama's Little Function App! Goodbye!

    */
}//end class MamasFunctionDemoDriver