Answer the question
In order to leave comments, you need to log in
Why doesn't my shitcode listen to my bike?
Actually, here is the code. Only simplified and reduced by the number of lines every 10 times.
It implies a test in which if there are more answers "A" - then the result is one, and if there are more answers "B" - another. If the same - the third.
I understand that there are methods that are much simpler, but for now I'm just gaining experience, and I went with the piling up method, but, on the other hand, understandable to me.
//до метода onCreate
int q1A;
int q1B;
int q1C;
int q2A;
int q2B;
int q2C;
int q3A;
int q3B;
int q3C;
int q4A;
int q4B;
int q4C;
int ballA;
int ballB;
String resText;
...
//метод onClick, q1 - question1, a2 - answer 2.
RadioButton q1_a1 = (RadioButton) findViewById(R.id.q1_a1);
RadioButton q1_a2 = (RadioButton) findViewById(R.id.q1_a2);
RadioButton q2_a1 = (RadioButton) findViewById(R.id.q2_a1);
RadioButton q2_a2 = (RadioButton) findViewById(R.id.q2_a2);
RadioButton q3_a1 = (RadioButton) findViewById(R.id.q1_a3);
RadioButton q3_a2 = (RadioButton) findViewById(R.id.q1_a3);
RadioButton q4_a1 = (RadioButton) findViewById(R.id.q1_a4);
RadioButton q4_a2 = (RadioButton) findViewById(R.id.q1_a4);
if (q1_a1.isChecked()) q1A = 1; else q1A = 0;
if (q1_a2.isChecked()) q1B = 1; else q1B= 0;
if (q2_a1.isChecked()) q2A = 1; else q2A = 0;
if (q2_a2.isChecked()) q2B = 1; else q2B = 0;
if (q3_a1.isChecked()) q3A = 1; else q3A = 0;
if (q3_a2.isChecked()) q3B = 1; else q3B = 0;
if (q4_a1.isChecked()) q4A = 1; else q4A = 0;
if (q4_a2.isChecked()) q4B = 1; else q4B = 0;
ballA = q1A + q2A + q3A + q4A;
ballB = q1B + q2B + q3B + q4B;
int prover = ballA + ballB;
if (prover < 4)
resText = "Один или более вопросов остались без ответа. Пожалуйста, ответьте для достижения более точно результата.";
else {
if (ballA != ballB) {
if (ballA > ballB)
resText = "Результат 1.";
if (ballB > ballA)
resText = "Результат 2.";
}
if (ballA == ballB){
if (ballA == ballB)
resText = "Среднее между результатом 1 и результатом 2.";
}
}
TextView resulText = (TextView) findViewById(R.id.resultText);
resultText.setText(resText);
Answer the question
In order to leave comments, you need to log in
Full code. Decided.
The problem was that when comparing the answers, he counted as equal those that were equal to zero. And that's why I didn't get the same result. All that was left was to add something like ballA != 0 to each condition for intermediate results, and the problem was solved. I missed it, really.
//до метода onCreate
String resText;
int q1A;
int q1B;
int q1C;
int q1D;
int q2A;
int q2B;
int q2C;
int q2D;
int q3A;
int q3B;
int q3C;
int q3D;
int q4A;
int q4B;
int q4C;
int q4D;
int q5A;
int q5B;
int q5C;
int q5D;
int ballA;
int ballB;
int ballC;
int ballD;
...
//метод onClick
public void t17_getResult(View view) {
RadioButton rb11 = (RadioButton) findViewById(R.id.t17_q1_a1);
RadioButton rb12 = (RadioButton) findViewById(R.id.t17_q1_a2);
RadioButton rb13 = (RadioButton) findViewById(R.id.t17_q1_a3);
RadioButton rb14 = (RadioButton) findViewById(R.id.t17_q1_a4);
RadioButton rb21 = (RadioButton) findViewById(R.id.t17_q2_a1);
RadioButton rb22 = (RadioButton) findViewById(R.id.t17_q2_a2);
RadioButton rb23 = (RadioButton) findViewById(R.id.t17_q2_a3);
RadioButton rb24 = (RadioButton) findViewById(R.id.t17_q2_a4);
RadioButton rb31 = (RadioButton) findViewById(R.id.t17_q3_a1);
RadioButton rb32 = (RadioButton) findViewById(R.id.t17_q3_a2);
RadioButton rb33 = (RadioButton) findViewById(R.id.t17_q3_a3);
RadioButton rb34 = (RadioButton) findViewById(R.id.t17_q3_a4);
RadioButton rb41 = (RadioButton) findViewById(R.id.t17_q4_a1);
RadioButton rb42 = (RadioButton) findViewById(R.id.t17_q4_a2);
RadioButton rb43 = (RadioButton) findViewById(R.id.t17_q4_a3);
RadioButton rb44 = (RadioButton) findViewById(R.id.t17_q4_a4);
RadioButton rb51 = (RadioButton) findViewById(R.id.t17_q5_a1);
RadioButton rb52 = (RadioButton) findViewById(R.id.t17_q5_a2);
RadioButton rb53 = (RadioButton) findViewById(R.id.t17_q5_a3);
RadioButton rb54 = (RadioButton) findViewById(R.id.t17_q5_a4);
if (rb11.isChecked()) q1A = 1; else q1A = 0;
if (rb12.isChecked()) q1B = 1; else q1B = 0;
if (rb13.isChecked()) q1C = 1; else q1C = 0;
if (rb14.isChecked()) q1D = 1; else q1D = 0;
if (rb21.isChecked()) q2A = 1; else q2A = 0;
if (rb22.isChecked()) q2B = 1; else q2B = 0;
if (rb23.isChecked()) q2C = 1; else q2C = 0;
if (rb24.isChecked()) q2D = 1; else q2D = 0;
if (rb31.isChecked()) q3A = 1; else q3A = 0;
if (rb32.isChecked()) q3B = 1; else q3B = 0;
if (rb33.isChecked()) q3C = 1; else q3C = 0;
if (rb34.isChecked()) q3D = 1; else q3D = 0;
if (rb41.isChecked()) q4A = 1; else q4A = 0;
if (rb42.isChecked()) q4B = 1; else q4B = 0;
if (rb43.isChecked()) q4C = 1; else q4C = 0;
if (rb44.isChecked()) q4D = 1; else q4D = 0;
if (rb51.isChecked()) q5A = 1; else q5A = 0;
if (rb52.isChecked()) q5B = 1; else q5B = 0;
if (rb53.isChecked()) q5C = 1; else q5C = 0;
if (rb54.isChecked()) q5D = 1; else q5D = 0;
ballA = q1A + q2A + q3A + q4A + q5A;
ballB = q1B + q2B + q3B + q4B + q5B;
ballC = q1C + q2C + q3C + q4C + q5C;
ballD = q1D + q2D + q3D + q4D + q5D;
int prover = ballA + ballB + ballC + ballD;
if (prover < 5)
resText = "Один или более вопросов остались без ответа. Пожалуйста, ответьте для достижения более точно результата.";
else {
if (ballA > ballB && ballA > ballC && ballA > ballD)
resText = "...Сангвиник...";
if (ballB > ballA && ballB > ballC && ballB > ballD)
resText = "...Меланхолик...";
if (ballC > ballA && ballC > ballB && ballC > ballD)
resText = "...Холерик...";
if (ballD > ballA && ballD > ballB && ballD > ballC)
resText = "...Флегматик...";
if (ballA != 0 && ballA == ballB)
resText = "...чем-то средним между сангвиником и меланхоликом...";
if (ballB != 0 && ballB == ballC)
resText = "... чем-то средним между меланхоликом и холериком... ";
if (ballC != 0 && ballC == ballD)
resText = "...чем-то средним между холериком и флегматиком...";
if (ballD != 0 && ballD == ballA)
resText = "...чем-то средним между флегматиком и сангвиником....";
}
TextView mResText17 = (TextView) findViewById(R.id.t17_resText);
mResText17.setText(resText);
}
Lots of the same. Arrays and loops will help reduce.
Also it is not necessary to declare the list of variables thus.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question