Android Studio constellation query system

The constellation query system judges the corresponding constellation of the user according to the date of birth entered by the user, and can also realize the user's today's fortune

demand analysis

  1. The layout of the query system mainly uses TextView, EditView and Button
  2. The core of the system is how to judge the year, month and corresponding constellation entered by the user

 The logic code for judging the corresponding constellation

Because judging the constellation only needs the year and month, I did not get the year

DatePicker dp_1_select=findViewById(R.id.dp_1_select);
int month = dp_1_select.getMonth()+1;//获取月份,这里+1是因为获取的月份会比选择的月份少1
int day = dp_1_select.getDayOfMonth();//获取日
double date_now=month+(double)day/100;//将月和日合并,比如说1月2日,那就是1.02,这在后面判断会比较方便

Use if to judge the corresponding year and month

               if(date_now>=1.20 && date_now<=2.18){//水平座
                    Intent intent = new Intent(Select_Screen.this, Aquarious.class);
                    intent.putExtra("Name",name);//将用户的名字传到对应界面
                    intent.putExtra("str1",str1);//将今日的运势传到对应界面
                    startActivity(intent);       //跳转界面
                }else if(date_now>=2.19 && date_now<=3.20){//双鱼座
                    Intent intent = new Intent(Select_Screen.this, Pisces.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now>=3.21 && date_now<=4.19){//白羊座
                    Intent intent = new Intent(Select_Screen.this, Aries.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now>=4.20 && date_now<=5.20){//金牛座
                    Intent intent = new Intent(Select_Screen.this, Taurus.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now>=5.21 && date_now<=6.21){//双子座
                    Intent intent = new Intent(Select_Screen.this, Gemini.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now >=6.22 && date_now<=7.22){//巨蟹座
                    Intent intent = new Intent(Select_Screen.this, Cancer.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now>=7.23 && date_now<=8.22){//狮子座
                    Intent intent = new Intent(Select_Screen.this, Leo.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now>=8.23 && date_now<=9.22){//处女座
                    Intent intent = new Intent(Select_Screen.this, Virgo.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now>=9.23 && date_now<=10.23){//天秤座
                    Intent intent = new Intent(Select_Screen.this, Libra.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now>=10.24 && date_now<=11.22){//天蝎座
                    Intent intent = new Intent(Select_Screen.this, Scorpio.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else if (date_now>=11.23 && date_now<=12.21){//射手座
                    Intent intent = new Intent(Select_Screen.this, Sagittarius.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }else {                                      //摩羯座
                    Intent intent = new Intent(Select_Screen.this, Capricorn.class);
                    intent.putExtra("Name",name);
                    intent.putExtra("str1",str1);
                    startActivity(intent);
                }
As long as you set the corresponding interface layout, you can realize the horoscope query. If you want to improve the horoscope for the day, it is also possible.
String[] str={"今日运势一般,不要活在自己的梦想里,要懂得认清现实",
              "今日运势还行,心胸比较开阔,不会为了一点小事就自寻烦恼",
              "今日运势泛泛,对着别人的额优秀不要抱有嫉妒的心理,而是要学着向对方看齐",
              "今日运势良好,走自己的路,让别人说去吧",
              "今日运势中等,跟讲不清道理的人就不要再继续政治下去,你无法改变一个人的三观",
              "今日运势尚可,不要瞻前顾后,想到什么就立马行动去做",
              "今日运势较好,春光明媚,可以出去感受一下大自然的美好",
              "今日运势平平,无论什么时候都不要自我感动",
              "今日运势不错,遇事不要抱怨,先想想解决方法,这才是所谓的成长",
              "今日运势中等,不要什么事都刨根究底,并不一定能得到想要的答案",
              "今日运势尚好,具备一定的目标感,可以抵制外界的诱惑,坚定不移的朝前走",
              "今日运势一般,打开眼界,多看看外面的世界,不要成为井底之蛙",
              };
 Random random=new Random();
 int num=random.nextInt(12);
 String str1;
 switch (num){
     case 0:str1=str[0];break;
     case 1:str1=str[1];break;
     case 2:str1=str[2];break;
     case 3:str1=str[3];break;
     case 4:str1=str[4];break;
     case 5:str1=str[5];break;
     case 6:str1=str[6];break;
     case 7:str1=str[7];break;
     case 8:str1=str[8];break;
     case 9:str1=str[9];break;
     case 10:str1=str[10];break;
     case 11:str1=str[11];break;
     default:
          throw new IllegalStateException("Unexpected value: " + num);
             }
  1.  The str string array stores some statements about today's fortune
  2. Call a Random function to get a random number and assign the value of the random number to num
  3. Determine the corresponding num value, and assign the corresponding statement in the str string array to str1
  4. Pass intent.putExtra("str1", str1); to the corresponding interface for display

 The core sentence of today's fortune is to obtain random numbers and judge random numbers

 

Display the transmitted string in another interface

String str1=intent.getStringExtra("str1");//获得传过来的字符串,str1必须和传进来的变量名保持一致
TextView tv_11=findViewById(R.id.tv_11);
tv_11.setText(str1);//将str1字符串显示在文本框中

The final rendering is like this

 

 

Guess you like

Origin blog.csdn.net/weixin_54284906/article/details/125054647