Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.upr1
- import androidx.appcompat.app.AppCompatActivity
- import android.os.Bundle
- import android.view.View
- import android.widget.EditText
- import android.widget.TextView
- class MainActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- }
- fun btn_go( view:View ) {
- // Връзка с контролите на екрана
- val edName=findViewById<EditText>(R.id.editTextTextPersonName)
- val tv=findViewById<TextView>(R.id.textView)
- val ime=edName.text.toString()
- //1
- //val godini=findViewById<EditText>(R.id.editTextNumber).text.toString().toInt()
- //2
- val edAge=findViewById<EditText>(R.id.editTextNumber)
- val tmp=edAge.text.toString()
- // Ако няма въведена възраст да прекъсне функцията
- if( tmp.isEmpty() ) return
- val godini=tmp.toInt()
- if( ime.length>0) tv.text="Здравей, "+ime
- else tv.text="Въведете името си"
- // Коя година е роден
- val born=2022-godini
- val tv2=findViewById<TextView>(R.id.textView2)
- if(godini>100) {
- tv2.text="Каква е тази възраст?"
- return
- } else tv2.text="Роден си през "+born+" година"
- // Изведете вида възраст: дете, тинейджър, младеж, възрастен, стар
- val tv3=findViewById<TextView>(R.id.textView3)
- if(godini<11) tv3.text="Дете"
- //1
- /*else if(godini<20) tv3.text="Тинейджър"
- else if(godini<30) tv3.text="Младеж"
- else if(godini<67) tv3.text="Възрастен"*/
- //2
- if(godini>=11 && godini<20) tv3.text="Тинейджър"
- if(godini>=20 && godini<30) tv3.text="Младеж"
- if(godini>=30 && godini<67) tv3.text="Възрастен"
- if(godini>=67) tv3.text="Стар"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement