用eclipse编写星座查询程序

用eclipse编写星座查询程序,第1张

我也是在网上找的 有简单的 你先看看这个吧

package 星座

import java.awt.BorderLayout

import java.awt.FlowLayout

import java.awt.event.ActionEvent

import java.awt.event.ActionListener

import java.util.Calendar

import javax.swing.JButton

import javax.swing.JFrame

import javax.swing.JLabel

import javax.swing.JPanel

import javax.swing.JTextField

public class Constellation implements ActionListener{

private JFrame frame = null

private JTextField year = null

private JTextField month = null

private JTextField day = null

private JLabel label1 = null

private JLabel label2 = null

private JLabel label3 = null

private JPanel panel1 = null

private JPanel panel2 = null

private JButton button = null

private JTextField output = null

public static final String[] zodiacArr = {

import java.text.ParseException

import java.text.SimpleDateFormat

import java.util.Calendar

import java.util.Date

import java.util.Scanner

public class Test {

    public static void main(String[] args) throws ParseException {

        Scanner scanner = new Scanner(System.in)

        

        // 只输入月、日,此代码未校验月、日输入是否合理,比如2月30

        System.out.print("请输入你的出生月份")

        int month = scanner.nextInt()

        System.out.print("请输入你的出生日期")

        int day = scanner.nextInt()

        System.out.print("你的星座是:")

        

        // 通过输入完整日期的方式判断,可以自动处理不合理日期,比如2月30

        // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd")

        // System.out.print("请输入你的出生日期(形如2018-02-03):")

        // Date birthday = dateFormat.parse(scanner.nextLine())

        //

        // Calendar calendar = Calendar.getInstance()

        // calendar.setTime(birthday)

        // int month = calendar.get(Calendar.MONTH) + 1

        // int day = calendar.get(Calendar.DAY_OF_MONTH)

        // System.out.print("你的生日是 :" + dateFormat.format(birthday) + "\r\n你的星座是:")

        scanner.close()

        switch (month) {

        case 1:

            if (day < 22)

                System.out.println("摩羯座")

            else

                System.out.println("水瓶座")

            break

        case 2:

            if (day < 22)

                System.out.println("水瓶座")

            else

                System.out.println("双鱼座")

            break

        case 3:

            if (day < 22)

                System.out.println("双鱼座")

            else

                System.out.println("白羊座")

            break

        case 4:

            if (day < 22)

                System.out.println("白羊座")

            else

                System.out.println("金牛座")

            break

        case 5:

            if (day < 22)

                System.out.println("金牛座")

            else

                System.out.println("双子座")

            break

        case 6:

            if (day < 22)

                System.out.println("双子座")

            else

                System.out.println("巨蟹座")

            break

        case 7:

            if (day < 22)

                System.out.println("巨蟹座")

            else

                System.out.println("狮子座")

            break

        case 8:

            if (day < 22)

                System.out.println("狮子座")

            else

                System.out.println("处女座")

            break

        case 9:

            if (day < 22)

                System.out.println("处女座")

            else

                System.out.println("天枰座")

            break

        case 10:

            if (day < 22)

                System.out.println("天枰座")

            else

                System.out.println("天蝎座")

            break

        case 11:

            if (day < 22)

                System.out.println("天蝎座")

            else

                System.out.println("射手座")

            break

        case 12:

            if (day < 22)

                System.out.println("射手座")

            else

                System.out.println("摩羯座")

        }

    }

}

定义一个String类;

使用接收格式为(xx/xx)

使用Stringbuffer分割为两个int类型

month(月) day(日)

switch(month){

case 1:

if(day<=23){

system.out.print("....星座");

}else{

system.out.print("....星座");

}

black;

…………

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11868144.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存