Kotlin:根据日期获取星座


在群里看到一个同学的期末作业是根据日期返回星座,可能为了防止抄袭,要求加上诞生石。。

其实没啥区别啊。。。

下面是代码:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val (inputM,inputD,goBtn,outText)  = arrayOf(
            findViewById(R.id.inputMonth),
            findViewById(R.id.inputDay),
            findViewById

null

工具类:

package com.simplewen.win0.checkluckybound

class Constellation{
    companion object {
        fun star(m:Int,d:Int):String{
            var res = "格式错误!"
            val date = intArrayOf(20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22)
            val index = m//索引
            val luckyData = arrayListOf>(
                mapOf("星座:" to "摩羯座,诞生石:土耳其玉" ),
                mapOf("星座:" to "水瓶座,诞生石:紫水晶"),
                mapOf("星座:" to "双鱼座,诞生石:月长石" ),
                mapOf("星座:" to "白羊座,诞生石:钻石" ),
                mapOf("星座:" to "金牛座,诞生石:蓝宝石" ),
                mapOf("星座:" to "双子座,诞生石:玛瑙" ),
                mapOf("星座:" to "巨蟹座,诞生石:珍珠" ),
                mapOf("星座:" to "狮子座,诞生石:红宝石"),
                mapOf("星座:" to "处女座,诞生石:红条纹玛瑙" ),
                mapOf("星座:" to "天秤座,诞生石:蓝宝石" ),
                mapOf("星座:" to "天蝎座,诞生石:猫眼石" ),
                mapOf("星座:" to "射手座,诞生石:黄宝石" ),
                mapOf("星座:" to "摩羯座,诞生石:土耳其玉")
            )
            when(m){
                1,2,3,4,5,6,7,8,9,10,11,12->{
                    when(d){
                        in  1..31 ->
                            if(d < date[m-1]){
                                res = luckyData[index-1]["星座:"].toString()
                            }else{

                                res = luckyData[index]["星座:"].toString()
                            }
                        else -> res  = "天数格式错误!"
                    }

                }
                else ->{
                     res = "月份格式错误!"
                   
                }
            }

            return res
        }
    }

}

null

其实也没什么区别。

下面是图

null


文章作者: 2winter
文章链接: https://2winter.com
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 2winter !
  目录