2017-03-02 54 views
0

編寫一個程序,該程序將添加一個人的出生日期的數字以獲取一位數字以生成命理報告。班級分配命理報告Java代碼

下面是我的代碼,它大多是完整的,但我不知道它是否正確,因爲當我嘗試編譯它時,出現錯誤消息,我需要';'第一次之後,但是當我加入;它只是給了我更多的錯誤。任何幫助表示讚賞謝謝!

import java.util.Scanner;

公共類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; 
     } 
    } 

} 
+0

其中,閏年邏輯不正確,不需要'leapyear'變量。 'while'從句是混亂的,大多數什麼都不做。 –

回答

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(); 
    } 
}