2017-03-02 2 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(); 
    } 
}