public void neutralize(Beaker beaker)
        {
            float H  = beaker.getComponentVolume(ChemNotation.ion_H);
            float OH = beaker.getComponentVolume(ChemNotation.ion_OH);

            if (H > 0 && OH > 0)
            {
                int[] reactionRatio = densityToReactionRatio();

                // Because without reaction, amount of positive ion : negative ion = 1 : 1
                float OH_by_K  = beaker.getComponentVolume(ChemNotation.ion_K);
                float OH_by_Na = OH - OH_by_K;

                // Need to optimize those algorithms..
                if (H / reactionRatio[0] > OH_by_K / reactionRatio[1] + OH_by_Na / reactionRatio[2])
                {
                    beaker.removeBeakerComponent(ChemNotation.ion_H, H - (H / reactionRatio[0] - (OH_by_K / reactionRatio[1] + OH_by_Na / reactionRatio[2])));
                    beaker.removeBeakerComponent(ChemNotation.ion_OH, OH);
                    beaker.addBeakerComponent(ChemNotation.H2O, OH);
                }
                else
                {
                    beaker.removeBeakerComponent(ChemNotation.ion_H, H);
                    beaker.removeBeakerComponent(ChemNotation.ion_OH, OH - (OH_by_K / reactionRatio[1] + OH_by_Na / reactionRatio[2] - H / reactionRatio[0]));
                    beaker.addBeakerComponent(ChemNotation.H2O, H);
                }
            }
        }
Ejemplo n.º 2
0
        private void HClBeaker_LeftMouseDownEvent(object sender, MouseButtonEventArgs e)
        {
            UserInputPrompt prompt = new UserInputPrompt("얼마나 넣을 건가요?");

            try
            {
                // Every passed value(propmpt.userInputText) is proved convertible & positive
                if (prompt.ShowDialog() == true)
                {
                    defaultBeaker.addBeakerComponent(ChemNotation.ion_Cl, Convert.ToSingle(prompt.userInputText));
                }
            }
            catch (OverflowException)
            {
                MessageBox.Show("수가 너무 큽니다!", "이런!");
            }

            renewBeakerStatus();
            defaultBeaker.neutralize(defaultBeaker);
        }