// Terminal2 Class
/** Created by:
 *             Jonathan Kensler
 *             Yaw A. Nti-Addae
 *             Patric Knoedler
 */

import SimpleInput;
import SimpleOutput;
import Coordinator2;
import InstructorNotifier2;
import OurSinglyLinkedList2;
import SchemeTesterInterface2;

public class Terminal2 implements SchemeTesterInterface2{

    /** The printer method takes the results of testing the code from the
     * outputformatter and displays it on the screen.And gives the user
     * the option to send it to the instructor, redo the process or quit.
     */
    public void printer(String results) {

        SimpleOutput out = new SimpleOutput ();
        SimpleInput in = new SimpleInput ();
        InstructorNotifier2 notifier = new InstructorNotifier2();
        Terminal2 redo = new Terminal2();

        out.println(results);

        // prompt user is the format is ok.
        String option;
        boolean stop = false;

        while (!stop) {
            out.println("   S - Send This to Instructor");
            out.println("   R - Redo Process");
            out.println("   Q - Quit program and not send to Instructor");

            option = in.readString();
            switch (option.charAt(0))
                {
                case 'S':
                case 's':
                    notifier.sendEmail("addressee", "sender", "subject", results);
                    break;
                case 'R':
                case 'r':
                    redo.terminal2();
                    break;
                case 'Q':
                case 'q':
                    stop = true;
                    break;
                default: out.println ("Invalid Option - Try Again!");
                }
        }// while
    }// printer(String)

    /**
     * The terminal2 method reads in the information of the user and send
     * them to the coordinator.
     */
    public static void terminal2() {
        SimpleInput in = new SimpleInput ();
        SimpleOutput out = new SimpleOutput ();
        Coordinator2 coordinator = new Coordinator2();

        String username = new String();
        double labname=0;
        String filename = new String();
        String spfilename = new String();
        String interfacename = "Terminal2";
        String confirmer = "no";

        out.println("Instructions");
        while (!confirmer.equals("yes")) {
            out.println("Enter Name");
            username = in.readString();
            out.println("The name entered is " + username);
            out.println("If this is the desired entry? press yes else no");
            confirmer = in.readString();
        }//while for name
        confirmer = "no";
        while (!confirmer.equals("yes")) {
            out.println("Enter Lab Number");
            labname = in.readDouble();
            out.println("The name entered is " + labname);
            out.println("If this is the desired entry? press yes else no");
            confirmer = in.readString();
        }//while for labname
        confirmer = "no";
        while (!confirmer.equals("yes")) {
            out.println("Enter filename");
            filename = in.readString();
            out.println("The name entered is " + filename);
            out.println("If this is the desired entry? press yes else no");
            confirmer = in.readString();
        }//while for filename
        confirmer = "no";
        while (!confirmer.equals("yes")) {
            out.println("Do you have a special test case file?");
            out.print("If you do, enter the name of that file.");
            out.println("If not, press Enter");
            spfilename = in.readString();
            out.println("The name entered is " + spfilename);
            out.println("If this is the desired entry? press yes else no");
            confirmer = in.readString();
        }//while for spfilename

        out.println("");
        out.println("Here is the Information entered");
        out.println("User Name: " + username);
        out.println("Lab Number: " + labname);
        out.println("File Name: " + filename);
        out.println("Special Test Case File Name: " + spfilename);

        // Call Coordinator2
        try {
            coordinator.dostuff(username,
                                labname,
                                filename,
                                spfilename,
                                this);
        } catch (Exception e) {}
    } // terminal()


    public static void main (String [] args ) {

        terminal2();

    } //main
}// Terminal2
