Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oek.colledge.quiz3pr
- import android.content.Intent
- import android.os.Bundle
- import android.widget.Button
- import android.widget.TextView
- import android.widget.Toast
- import androidx.appcompat.app.AppCompatActivity
- import org.w3c.dom.Text
- class MainActivity : AppCompatActivity() {
- var question = listOf(
- "Сколько будет 2 + 2?\n\nA) 4\n\nB) 5\n\nC) 6",
- "Какие основные языки программирования для Android?\n\nA) Kotlin и Java\n\nB) Python и Java\n\nC) C++ и C#",
- "Как называется окно в Android приложении?\n\nA) Activity\n\nB) Dialog\n\nC) Fragment"
- )
- var rightAnswer = listOf(1, 1, 1)
- var questionIndex = -1
- var answers: MutableList<Int> = mutableListOf()
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- UpdateQuestion()
- findViewById<Button>(R.id.button1).setOnClickListener {
- GetAnswer(1)
- }
- findViewById<Button>(R.id.button2).setOnClickListener {
- GetAnswer(2)
- }
- findViewById<Button>(R.id.button3).setOnClickListener {
- GetAnswer(3)
- }
- }
- fun GetAnswer(answer: Int) {
- if (answer == rightAnswer[questionIndex]) {
- Toast.makeText(this, "Верно!", Toast.LENGTH_SHORT).show()
- answers.add(1)
- UpdateQuestion()
- } else {
- answers.add(-1)
- Toast.makeText(this, "Неверно!", Toast.LENGTH_SHORT).show()
- }
- }
- fun UpdateQuestion() {
- questionIndex++
- if (questionIndex < question.size) {
- findViewById<TextView>(R.id.tvQuest).text = question[questionIndex]
- return
- }
- Toast.makeText(this, "Тест завершен!", Toast.LENGTH_SHORT).show()
- var intentResult = Intent(this, ResultTestActivity::class.java)
- var score = answers.sum()
- intentResult.putExtra("score", score)
- intentResult.putExtra("countQuestion", question.size)
- startActivity(intentResult)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement