0

I'm confused on how can I open another activity after finishing the array count and how can i pass the value of score.

I'm new to android that's why I'm confused, I'm Sorry T_T.

this is my code:

  package com.letsgo.finalsjavaandroid;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


public class Quest1 extends AppCompatActivity {

    private Superclass qClass = new Superclass();
    private TextView txtScores;
    private TextView txtQuestionss;
    private Button Choices1;
    private Button Choicess2;
    private Button Choicess3;


    private String answers;
    private int scoring = 0;
    private int questnum = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quest1);

        txtScores = (TextView)findViewById(R.id.txtScore);
        txtQuestionss = (TextView)findViewById(R.id.txtQuestions);
        Choices1 = (Button) findViewById(R.id.btnChoice1);
        Choicess2 = (Button)findViewById(R.id.btnChoice2);
        Choicess3 = (Button) findViewById(R.id.btnChoice3);

    updateQuestions();
        Choices1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Choices1.getText()== answers){
                    scoring = scoring + 1;
                    updateScore(scoring);
                    updateQuestions();

                    Toast.makeText(Quest1.this, "Correct", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(Quest1.this, "Wrong", Toast.LENGTH_SHORT).show();
                    updateQuestions();
                }
            }
        });

        Choicess2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Choicess2.getText()== answers){
                    scoring = scoring + 1;
                    updateScore(scoring);
                    updateQuestions();

                    Toast.makeText(Quest1.this, "Correct", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(Quest1.this, "Wrong", Toast.LENGTH_SHORT).show();
                    updateQuestions();
                }
            }
        });

        Choicess2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Choicess2.getText()== answers){
                    scoring = scoring + 1;
                    updateScore(scoring);
                    updateQuestions();

                    Toast.makeText(Quest1.this, "Correct", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(Quest1.this, "Wrong", Toast.LENGTH_SHORT).show();
                    updateQuestions();
                }
            }
        });





    }
    private void updateQuestions(){
        txtQuestionss.setText(qClass.getQuestions(questnum));
        Choices1.setText(qClass.Choice1(questnum));
        Choicess2.setText(qClass.Choice2(questnum));
        Choicess3.setText(qClass.Choice3(questnum));

        answers = qClass.Answers(questnum);
        questnum++;

    }



    private void updateScore(int point){
        txtScores.setText(""+ scoring);
    }
}

and this is the code for superclass:

public class SuperClass {

    private String Quests[] = {
        "In the anime series Full Metal Alchemist, what do Alchemists consider the greatest taboo?",
            "Who is the protagonist of Boku no hero Academia",
            "Who is the sister of byakuya in bleach",
            "What's the name of the antagonist who put a hole in goku's body",
            "Who is Naruto's father"
    };

    private String Choices [][] = {
            { "Human Transmutation","Magic","Killing"},
            {"Bakugo","Deku","All Might"},
            {"Rukia","Orihime","Doraemon"},
            {"Cell","Buu","Rize"},
            {"Jiraiya","Iruka","Minato"}


    };

    private String CorrectAnswers [] =
            {"Human Transmutation","Deku","Rukia","Cell","Minato"};


    public String getQuestions(int a ){
       String question = Quests[a];
        return question;

    }

    public String Choice1(int a){
        String Choice0 = Choices[a][0];
        return Choice0;


    }
    public String Choice2(int a){
        String Choice01 = Choices[a][1];
        return Choice01;


    }
    public String Choice3(int a){
        String Choice02 = Choices[a][2];
        return Choice02;


    }

    public String Answers(int a ){
        String answer = CorrectAnswers[a];
        return answer;

    }

}

In advance, Thanks for helping me UwU Sorry for adding unnecessary words it's just my post is mostly code that's why i need to post some.

  • What do you mean by "finishing the array"? – Code-Apprentice Apr 17 '20 at 16:29
  • the array count I think, there are 5 questions after finishing those another activity will open – Kuga Terunori Apr 17 '20 at 16:31
  • Let's back up a step. What do you want your app to do? What will the user see on the screen? What does the user do? And what happens for each of those user actions? – Code-Apprentice Apr 17 '20 at 16:31
  • As to the direct answer to your question, check the link I added to the top of the page. It shows how to start another Activity in your app. – Code-Apprentice Apr 17 '20 at 16:34
  • after the user taps the choices 5 times another activity will appear that means the quiz has ended and the score will be in the activity that just appeared. – Kuga Terunori Apr 17 '20 at 16:34
  • I suggest that you modify your code to make it more manageable. You should create a `Question` class that has the text of the question, the choices the user will see, and the correct answer. Then you can make an array of Question objects. – Code-Apprentice Apr 17 '20 at 16:36
  • You can also make a QuestionActivity that displays a **single** question. And using the techniques in the link at the top of this page, you start a new Activity for each question and then the final question starts the scoring activity. – Code-Apprentice Apr 17 '20 at 16:38

0 Answers0