课程作业命理报告Java代码

时间:2017-03-02 15:51:42

标签: java debugging compiler-errors

编写一个程序,该程序将添加一个人的出生日期的数字,以获得单个数字以生成数字命理报告。

下面是我的代码,它大部分是完整的,但我不知道它是否正确,因为当我尝试编译它时,我收到一条错误消息,我需要';'第一次之后,但是当我加入的时候;它只是给了我更多的错误。感谢您的任何帮助谢谢!

import java.util.Scanner;

public class rneely_Numerology {

    public static void main (String args [])
    {
        int date = 0;
        int sum;
        int day = 0;
        int month = 0;
        int year = 0;
        int numerology = 0;
        int tempnumerology = 0;
        char A;
        char B;
        int leapyear = 0;

        leapyear = year % 4;

        Scanner input = new Scanner (System.in);

        do {
            System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
            month = input.nextInt();
            A = input.next().charAt(0);
            day = input.nextInt();
            B = input.next().charAt(0);
            year = input.nextInt();
        }
        while (month < 1 || month > 12)
            {
                System.out.printf ( "Bad month: %d\n", month);
                System.out.println();
                System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 );
            {
                if (day < 1 || day > 31)
                {
                    System.out.printf ( "Bad day: %d\n", day);
                    System.out.println();
                }
                System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                                                                                   B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (month == 4 || month == 6 || month == 9 || month == 11);
            {
                if (day < 1 || day > 30)
                {
                    System.out.printf ( "Bad day: %d\n", day);
                    System.out.println();
                }

                System.out.print ( "Enter the birth day (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (month == 2);
            {
                if (year % 400 = 0) {
                    if (year % 100 = 0) {}}
                else if (year % 4 = 0)
                {
                    if (day < 1 || day > 29)
                    {
                        System.out.printf ( "Bad day for %d%d: %d\n", month, year, day);
                        System.out.println();
                    }
                }
                else
                {
                    if (day < 1 || day > 28)
                    {
                        System.out.printf ( "Bad day for %d%d: %d\n", month, year, day);
                        System.out.println();
                    }
                }

                System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (year < 1880 || year > 2280);
            {
                System.out.printf ( "Bad year: %d\n", year);
                System.out.println();
                            System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
                month = input.nextInt();
                A = input.next().charAt(0);
                day = input.nextInt();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while (A != '/' || B != '/');

            System.out.print ( "Use forward slashes between month, day, and year!\n" );
            System.out.println();
            System.out.print ( "Enter the birth date (mm/dd/yyyy): ");
            month = input.nextInt();
            A = input.next().charAt(0);
            day = input.next.Int();
            B = input.next().charAt(0);
            year = input.nextInt();



            date = month + day + year;
            for ( int numerology = date; numerology <= 9; numerology %= 10 ) {
                date = numerology;
            }

            System.out.printf ( "Welcome to the numerology report for %d/%d/%d\n", month, day, year);

            switch (numerology)
            {
                case 1:
                    System.out.println ( "-1- Hard work pays off in the future, laziness pays off now. ");
                    break;
                case 2:
                    System.out.println ( "-2- You learn from your mistakes... you will learn a lot today. ");
                    break;
                case 3:
                    System.out.println ( "-3- Your high minded principles spell success. ");
                    break;
                case 4:
                    System.out.println ( "-4- A dream you have will come true. ");
                    break;
                case 5:
                    System.out.println ( "-5- The greatest risk is not taking one. ");
                    break;
                case 6:
                    System.out.println ( "-6- Your ability for accomplishment will follow with success. ");
                    break;
                case 7:
                    System.out.println ( "-7- You will travel to many exotic places in your lifetime. ");
                    break;
                case 8:
                     System.out.println ( "-8- Keep your eye out for someone special. ");
                    break;
                case 9:
                    System.out.println ( "-9- Now is the time to try something new. ");
                    break;
            }
        }

    }

1 个答案:

答案 0 :(得分:0)

遵循的语法不正确。请在下面找到经过纠正的计划。

import java.util.Scanner;

public class Numerology {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        do {
            System.out.println("Enter the birth date (mm/dd/yyyy): ");
            String inp = input.nextLine();
            Integer month = null;
            Integer day = null;
            Integer year = null;
            try {
                String[] inpArr = inp.split("/");
                month = Integer.parseInt(inpArr[0]);
                day = Integer.parseInt(inpArr[1]);
                year = Integer.parseInt(inpArr[2]);
            } catch (Exception e) {
                System.out.println("Use forward slashes between month, day, and year!");
                continue;
            }
            String[] inpArr = inp.split("/");

            if (month < 1 || month > 12) {
                System.out.println("Bad Month : " + month);
                continue;
            }

            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                if (day < 1 || day > 31) {
                    System.out.println("Bad day: " + day);
                    continue;
                }
            } else if (month == 2) {
                if (year % 4 == 0) {
                    if (day < 1 || day > 29) {
                        System.out.println("Bad day: " + day);
                        continue;
                    }
                } else {
                    if (day < 1 || day > 28) {
                        System.out.println("Bad day: " + day);
                        continue;
                    }
                }
            } else {
                if (day < 1 || day > 30) {
                    System.out.println("Bad day: " + day);
                    continue;
                }
            }

            if (year < 1880 || year > 2280) {
                System.out.println("Bad year: " + year);
                continue;
            }

            String date = (month + day + year) + "";

            int sum = 11;
            while (sum > 10) {
                sum = 0;
                String[] dateArr = date.split("");
                for (int i = 0; i < dateArr.length; i++) {
                    sum += Integer.parseInt(dateArr[i]);
                }
                date = sum + "";
            }

            switch (sum) {
            case 1:
                System.out.println("-1- Hard work pays off in the future, laziness pays off now. ");
                break;
            case 2:
                System.out.println("-2- You learn from your mistakes... you will learn a lot today. ");
                break;
            case 3:
                System.out.println("-3- Your high minded principles spell success. ");
                break;
            case 4:
                System.out.println("-4- A dream you have will come true. ");
                break;
            case 5:
                System.out.println("-5- The greatest risk is not taking one. ");
                break;
            case 6:
                System.out.println("-6- Your ability for accomplishment will follow with success. ");
                break;
            case 7:
                System.out.println("-7- You will travel to many exotic places in your lifetime. ");
                break;
            case 8:
                System.out.println("-8- Keep your eye out for someone special. ");
                break;
            case 9:
                System.out.println("-9- Now is the time to try something new. ");
                break;
            }
            break;
        } while (true);
        input.close();
    }
}