2 Replies - 1554 Views - Last Post: 30 October 2013 - 03:58 AM Rate Topic: -----

#1 madsamps   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-October 13

Numerology Report

Posted 28 October 2013 - 06:58 PM

import java.util.Scanner;

public class msampsel_Numerology
{
    public static void main ( String args[])
    {
        int date = 0;
        int day = 0;
        int month = 0;
        int year = 0;
        int numerology = 0;
        char A;
        char B;
        int leap = 0;
        boolean valid = true;
        int quotient;
        int remainder;
        int sum = 0;

        leap = 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();
 // check month
            if (month < 1 || month > 12) {
                System.out.printf("Bad month:%d\n", month);
            }
            // check first slash
            else if (A != '/') {
                System.out.println("Use forward slashes between mm/dd/yyyy!");
            }
            else if (B != '/') {
                System.out.println("Use forward slashes between mm/dd/yyyy!");
            }
            else if (year < 1880 || year > 2280) {
                System.out.printf("Bad year: %d\n", year);
            }
            else {
                switch(month) {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:
                        if(day < 1 || day > 31)
                            System.out.printf("Bad day for %d/%d : %d\n", month, year, day);
                        else
                            valid = false;
                        break;
                    case 4:
                    case 6:
                    case 9:
                    case 11:
                        if(day < 1 || day > 30)
                            System.out.printf("Bad day for %d/%d : %d\n", month, year, day);
                        else
                            valid = false;
                        break;
                    case 2:
                        if(year % 400 == 0) // leap year
                            leap = 1;
                        else if (year % 100 == 0)
                            leap = 0;
                        else if(year % 4 == 0) // leap year
                            leap = 1;
                        else
                            leap = 0;

                        // leap year
                        if(leap == 1) {
                            if (day < 1 || day > 29)
                                System.out.printf("Bad day for %d/%d : %d\n", month, year, day);
 else
                                valid = false;
                        }
                        else{
                            if (day < 1 || day > 28)
                                System.out.printf("Bad day for %d/%d : %d\n", month, year, day);
                            else
                                valid = false;
                        }
                        break;
                    default:
                        System.out.println("Check your day!!!!");
                        break;
                }
            }
        }while(valid == true);
    }
 //Numerology
        Numerology();

        while (Numerology == 0 );
        {
            do {
                if (month > 9) {
                quotient = month / 10;
                remainder = month % 10;
                sum = sum + quotient + remainder;
                }
                else{
                sum = sum + month;
                }
                if (day > 9) {
                quotient = day / 10;
                remainder = day % 10;
                sum = sum + quotient + remainder;
                }
                else{
                sum = sum + day;
                }



Here is my code so far. Everything up until the Numerology part is correct. The program is supposed to take a birth date in mm / dd / yyyy format and add each number individually to outprint a message.

Example: 05 / 19 / 2013
0+5+1+9+2+0+1+3 = 21

Then, 2+1 = 3

Prints:
-3- Your wish has come true!

Like i said everything until the number adding part is correct and Im having a hard time.

Is This A Good Question/Topic? 0
  • +

Replies To: Numerology Report

#2 madsamps   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-October 13

Re: Numerology Report

Posted 28 October 2013 - 07:51 PM

Anything would help. Thank you!
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Numerology Report

Posted 30 October 2013 - 03:58 AM

  leap = year %4;


that does: leap = 0 % 4; so leap == 0

You need to perform this operation once there is a value in year :)

          System.out.print("Enter the birth date (mm/dd/yyyy): ");
          month = input.nextInt();


"03/21/1953" is not a int, you can't nextInt() on it. Do:
String line = input.nextLine();
String[] token = line.split("/");
int month = Integer.parseInt(token[0]);
int day = Integer.parseInt(token[1]);
int year = Integer.parseInt(token[2]);


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1