void CalcButt_Click(object sender, EventArgs e)
        {
            EditText nIn = FindViewById <EditText>(Resource.Id.editN);
            EditText pIn = FindViewById <EditText>(Resource.Id.editP);
            EditText rIn = FindViewById <EditText>(Resource.Id.editR);
            EditText aIn = FindViewById <EditText>(Resource.Id.editA);

            string nTxt = nIn.Text;
            string pTxt = pIn.Text;
            string rTxt = rIn.Text;
            string aTxt = aIn.Text;

            int    n = 0;
            double p = 0;
            int    r = 0;
            double a = 0;

            bool nInS;
            bool pInS;
            bool rInS;
            bool aInS;

            nInS = Int32.TryParse(nTxt, out n);
            pInS = double.TryParse(pTxt, out p);
            rInS = Int32.TryParse(rTxt, out r);
            aInS = double.TryParse(aTxt, out a);


            Toast nBad = Toast.MakeText(this, "n = " + nTxt + " is not valid", ToastLength.Short);
            Toast pBad = Toast.MakeText(this, "p = " + pTxt + " is not valid", ToastLength.Short);
            Toast rBad = Toast.MakeText(this, "r = " + rTxt + " is not valid", ToastLength.Short);
            Toast aBad = Toast.MakeText(this, "a = " + aTxt + " is not valid", ToastLength.Short);

            bool inError = false; // __________ Displaying Error Messages: __________

            if (!nInS)            // Error messages are only displayed if no previous errors were shown, so errors can be dealt with individually.
            {
                if (!inError)
                {
                    nBad.Show(); // Show error message
                    inError = true;
                }
            }
            if (!pInS || p > 1)
            {
                if (!inError)
                {
                    pBad.Show(); // Show error message
                    inError = true;
                }
            }
            if (!rInS || r > n)
            {
                if (!inError)
                {
                    rBad.Show(); // Show error message
                    inError = true;
                }
            }
            if (!aInS)
            {
                if (!inError)
                {
                    aBad.Show(); // Show error message
                    inError = true;
                }
            } // __________ End of Error Messages __________


            if (!inError)                                                              // Calculations only carried out if no parsing/maths errors were found.
            {
                TextView p_XetX     = FindViewById <TextView>(Resource.Id.p_XetX);     // First textview
                TextView p_XltORetX = FindViewById <TextView>(Resource.Id.p_XltORetX); // Second textview

                // Get values from Maths class and convert to string
                string p_XetX_string     = "P(X = x)= " + ((Maths.BinomialProb_XetR(n, p, r)).ToString("0.0000"));
                string p_XltORetX_string = "P(X ≤ x)= " + (Maths.BinomialProb_XltORetR(n, p, r)).ToString("0.0000");
                // Assign string values to label text
                p_XetX.Text     = p_XetX_string;
                p_XltORetX.Text = p_XltORetX_string;

                // Labels centred
            }
        }
Пример #2
0
        private void buttonCalc_Click(object sender, EventArgs e)
        {
            buttonCalc.Tag = "busy";
            ValuesAreOkay  = false;
            CalcSuccess    = false;

            // Read all numerical inout to strings
            string n_s = inputN.Text;
            string p_s = inputP.Text;
            string r_s = inputR.Text;
            string a_s = inputA.Text;

            VerifyValues(n_s, p_s, r_s, a_s);
            // Calls method to check variables parse and are within limits

            if (ValuesAreOkay)
            {
                NoTestSpec = false;

                string NullProbString = inputP.Text;
                radioButton1.Text = H1 + ":  p < " + NullProbString;
                radioButton2.Text = H1 + ":  p > " + NullProbString;
                radioButton3.Text = H1 + ":  p ≠ " + NullProbString;

                CalcSuccess = true;

                nValue = long.Parse(n_s);
                pValue = double.Parse(p_s);
                rValue = long.Parse(r_s);
                aValue = double.Parse(a_s);
                SetDefaultOutput(rValue);

                double P_XetR =
                    Maths.BinomialProb_XetR(nValue, pValue, rValue);
                string P_XetR_string = P_XetR.ToString("0.0000");
                text_P_XetR.Text += P_XetR_string;

                double P_XltR =
                    Maths.BinomialProb_XltR(nValue, pValue, rValue);
                string P_XltR_string = P_XltR.ToString("0.0000");
                text_P_XltR.Text += P_XltR_string;

                double P_XltetR =
                    Maths.BinomialProb_XltetR(nValue, pValue, rValue);
                string P_XltetR_string = P_XltetR.ToString("0.0000");
                text_P_XltetR.Text += P_XltetR_string;

                double P_XgtR =
                    Maths.BinomialProb_XgtR(nValue, pValue, rValue);
                string P_XgtR_string = P_XgtR.ToString("0.0000");
                text_P_XgtR.Text += P_XgtR_string;

                double P_XgtetR =
                    Maths.BinomialProb_XgtetR(nValue, pValue, rValue);
                string P_XgtetR_string = P_XgtetR.ToString("0.0000");
                text_P_XgtetR.Text += P_XgtetR_string;

                bool AltAcceptedBool =
                    Maths.IsAlternativeAccepted(testType, nValue, pValue, rValue, aValue);

                string stringAccept = "";
                string stringReject = "";
                if (AltAcceptedBool)
                {
                    stringAccept = "alternative";
                    stringReject = "null";
                }
                else
                {
                    stringAccept = "null";
                    stringReject = "alternative";
                }
                string stringHowAccept = "accepted";
                if (!AltAcceptedBool)
                {
                    stringHowAccept = "kept";
                }

                OutRejected.Text = "• The "
                                   + stringReject
                                   + " hypothesis has been rejected.";
                OutAccepted.Text = "• The "
                                   + stringAccept
                                   + " hypothesis has been "
                                   + stringHowAccept
                                   + ".";

                string OutConclusionString =
                    Strings.TestConclusion(false, "",
                                           testType, AltAcceptedBool, nValue, pValue);
                panelConclusion.Visible = true;

                OutConclusion.Text = OutConclusionString;
                Clipboard.SetText(OutConclusionString);
                // ^ Copy conclusion to clipboard

                string Comparison =
                    Strings.CriticalComparison(testType,
                                               nValue, pValue, rValue, aValue);

                OutComparisonValues.Text = Comparison;

                if (ShowExactValues)
                { // Exact values button has been clicked
                    string s1 = "P(X = x) = "
                                + P_XetR.ToString("0.00000000000000");
                    string s2 = "P(X < x) = "
                                + P_XltR.ToString("0.00000000000000");
                    string s3 = "P(X ≤ x) = "
                                + P_XltetR.ToString("0.00000000000000");
                    string s4 = "P(X > x) = "
                                + P_XgtR.ToString("0.00000000000000");
                    string s5 = "P(X ≥ x) = "
                                + P_XgtetR.ToString("0.00000000000000");

                    MessageBox.Show(s1 + "\n"
                                    + s2 + "\n"
                                    + s3 + "\n"
                                    + s4 + "\n"
                                    + s5,
                                    "Exact Values",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);

                    ShowExactValues = false;
                }
            }
            else
            {
                ValuesAreOkay   = false;
                ShowExactValues = false;
            }

            buttonCalc.Tag = "complete";
            headTitle.Focus();
        }