import TestGenerator2;
import RunSchemeTest2;
import ComparisonChecker2;
import OutputFormatter2;
import java.io.*;
import java.util.*;
import java.lang.Exception.*;

/**We will need to import the class of GUI, Terminal
 *Interface, Test Case Generator, Comparison Checker, 
 *Authority Program, User Program Object, Comparison 
 *Checker, and Output Formatter Object.
 */

public class Coordinator2{
    public void dostuff (String username,
                         double lab,
                         String location,
                         SchemeTesterInterface2 terminalInterface) 
                throws Exception {
        String usersprogram = location;
        String testcases = "";
        String compcheck = "";
        String authorityResults;
        String userResults;
        OurSinglyLinkedList2 results = null;
        File inputFile = new File("association.txt");
        FileReader in = new FileReader(inputFile);

        //read from association file
        int c;
        String line = "";

        while (!line.startsWith(new Double(lab).toString())){
            line = "";
        while ((c = in.read()) != -1){
            if (c == '\n'){
                break;}
            else {
                line += (char)c;}}
        }
        if ((c = in.read()) == -1) {
            throw new NoSuchFieldException
                ("The lab number entered does not exist!");
        }


        String testcasesfile = getTest(line);
        String authority_program = getAuthority(line);
        int levelcorrectness = getCorrectness(line);
        int maxchar = getMaxChar(line);
        int timeout = getMaxTime(line);

        /** We will be calling the methods for all other
         *classes, so we need objects of their classes to
         *call them on.
         */
        TestGenerator2 firsttestcasegenerator 
            = new TestGenerator2(testcasesfile);
        RunSchemeTest2 firstrunscheme 
            = new RunSchemeTest2(authority_program, timeout, maxchar);
        RunSchemeTest2 secondrunscheme 
            = new RunSchemeTest2(usersprogram, timeout, maxchar);
        ComparisonChecker2 firstcomparisonchecker = new ComparisonChecker2();

        while (firsttestcasegenerator.getTestCase() != "notestcases") {
            testcases = firsttestcasegenerator.getTestCase();
            // Run the test
            authorityResults = firstrunscheme.runTest(testcases);
            // Get the authority result
            userResults = secondrunscheme.runTest(testcases);
            // Get the user's results
            results.add(firstcomparisonchecker.compareResults(authorityResults, userResults));
            // Compare results
            results.add(firstcomparisonchecker.getStatistics());
            // Get Statistics
            }//while

            OutputFormatter2 firstoutputformatter = new OutputFormatter2();
            firstoutputformatter.OutputFormatter2(username, usersprogram, results, terminalInterface);

}// dostuff(lots of variables)

    public String getTest(String line){
        int I = line.indexOf(',');
        int E = line.indexOf(',', I + 1);
        return line.substring(I + 1, E - 1);
    }

    public String getAuthority(String line){
        int X = line.indexOf(',');
        int I = line.indexOf(',', X + 1);
        int E = line.indexOf(',', I + 1);
        return line.substring(I + 1, E - 1);
    }

    public int getCorrectness(String line){
        int X = line.indexOf(',');
        int Y = line.indexOf(',', X + 1);
        int I = line.indexOf(',', Y + 1);
        int E = line.indexOf(',', I + 1);
        int results = Integer.decode(line.substring(I + 1, E - 1)).intValue();
        return results;    
}

    public int getMaxChar(String line){
        int W = line.indexOf(',');
        int X = line.indexOf(',', W + 1);
        int Y = line.indexOf(',', X + 1);
        int I = line.indexOf(',', Y + 1);
        int E = line.indexOf(',', I + 1);
        int results = Integer.decode(line.substring(I + 1, E - 1)).intValue();
        return results;
    }

    public int getMaxTime(String line){
        int V = line.indexOf(',');
        int W = line.indexOf(',', V + 1);
        int X = line.indexOf(',', W + 1);
        int Y = line.indexOf(',', X + 1);
        int I = line.indexOf(',', Y + 1);
        int E = line.indexOf(',', I + 1);
        int results = Integer.valueOf(line.substring(I+1, E-1)).intValue();
        return results;
    }

}//class Coordinator


