1 Replies - 1050 Views - Last Post: 20 March 2014 - 01:47 AM Rate Topic: -----

#1 elconquistador   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-March 14

Numerology Report

Posted 19 March 2014 - 04:00 PM

This is a post from http://www.dreaminco...erology-report/ - I couldnt figure out how to quote it. Basically what i am trying to figure out is how to make required user input in the format, mm / dd / yyyy with spaces before and after the dashes.





 import java.util.Scanner;  

    

 public class Numerology {  

 

   private static int month, day, year, date, numerology;  

     private static char symbol, symbol2;  

    

     public static void main(String[] args) {  

    

        System.out.print("Enter your birth date (mm/dd/yyyy):");  

        Birthday();  

   }  

   

    //Asks for the users birthday, and goes on to check it.  

    private static void Birthday() {  

      String x = new Scanner(System.in).nextLine();  
        if (x.length() == 10) { //Checking the length of the date is correct (so nobody enters something like "1/2/94")  

           String temp = String.valueOf(x.charAt(0)) + String.valueOf(x.charAt(1));  

            month = Integer.parseInt(temp);  

           symbol = x.charAt(2);  

            temp = String.valueOf(x.charAt(3)) + String.valueOf(x.charAt(4));  

           day = Integer.parseInt(temp);  

           symbol2 = x.charAt(5);  

           year = Integer.parseInt(String.valueOf(x.substring(6)));  

           Check();  

      } else {  

         System.out.println("Bad date: put date in the format mm/dd/yy.");  
      }  

  }  

 

     //Checks each part of the date, and start numerology if the date is correct  

     private static void Check() {  

    

        //Check Month is correct  

      if (month < 1 || month > 12) {  

           System.out.printf("Bad month:%d\n", month);  

          System.out.print("Enter birth date (mm/dd/yyyy):");  

           Birthday();  

        } else //Check symbols are correct  

         if (symbol != '/' || symbol2 != '/') {  

            System.out.print("Use forward slashes between mm/dd/yyyy!\n");  

             System.out.print("Enter birth date (mm/dd/yyyy):");  

           Birthday();  

        } else // Check year is correct  

        if (year < 1880 || year > 2280) {  

             System.out.printf("Bad year for %d\n", year);  

            System.out.print("Enter birth date (mm/dd/yyyy):");  

            Birthday();  

        } else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {  

             if (day < 1 || day > 31) {  

                System.out.printf("Bad day for %d/%d : %d\n", month, year, day);  

                System.out.print("Enter birth date (mm/dd/yyyy):");  

                 Birthday();  

          }  

        } else if (month == 4 || month == 6 || month == 9 | month == 11) {  

            if (day < 1 || day > 30) {  

              System.out.printf("Bad day for %d/%d : %d\n", month, year, day);  

                System.out.print("Enter birth date (mm/dd/yyyy):");  

              Birthday();  

           }  

        } else if (month == 2) {  

           if (year % 4 == 0 || year % 400 == 0 || year == 2000) {  

               if (day < 1 || day > 29) {  

                 System.out.printf("Bad day for %d/%d : %d\n", month, year, day);  

             }  

              System.out.print("Enter birth date (mm/dd/yyyy):");  

                Birthday();  

            }  

            if (year % 4 != 0 || year % 100 == 0 || year % 400 != 0 || year != 2000) {  

               if (day < 1 || day > 28) {  

                   System.out.printf("Bad day for %d/%d : %d\n", month, year, day);  

                }  

             System.out.print("Enter birth date (mm/dd/yyyy):");  

              Birthday();  

            }  

     }  

       //Everything is good, go onto numerology.  

     Numerology();  

  }  

  //Starts numerology report  



  private static void Numerology() {  

       System.out.println("Welcome to the numerology report for " + month+ "/" + day+ "/" + year);  

      date = month + day + year;  

       do {  

     date = ((date % 10) + (date / 10));  

    } while (date >= 10);  

  numerology = date;  

  

 switch (numerology) {  

          case 1:  

           System.out.println(":1: Your luck is about to change so get ready! ");  

          break;  

             case 2:  

                 System.out.println(":2: Keep trying you are making it. ");  

                 break;  

             case 3:  

                 System.out.println(":3: It's time to relax! ");  

                 break;  

            case 4:  

                 System.out.println(":4: Money prolems are about to get solved. ");  

                 break;  

             case 5:  

                 System.out.println(":5: If you stay optimistic, your dreams will come true.");  

                break;  

             case 6:  

                 System.out.println(":6: Although things may seem bad, don't worry.");  

                 break;  

             case 7:  

                 System.out.println(":7: You are about to find the love of your life.");  

                break;  

            case 8:  

                System.out.println(":8: Too much fun is not very healthy.");  

                break;  

            case 9:  

                System.out.println(":9: Something unexpected will happen today.");  

                 break;  

         }  

    }  

 } 







Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Numerology Report

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3583
  • View blog
  • Posts: 16,393
  • Joined: 20-September 08

Re: Numerology Report

Posted 20 March 2014 - 01:47 AM

Quote

Basically what i am trying to figure out is how to make required user input in the format, mm / dd / yyyy with spaces before and after the dashes.


Why? That's not even a standard format (it has spaces) and you're just asking for trouble. Either use the standard format or prompt the user for month, then day, then year.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1