2 Replies - 3291 Views - Last Post: 23 October 2013 - 08:21 PM Rate Topic: -----

#1 madsamps  Icon User is offline

  • New D.I.C Head

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

question on numerology program

Posted 23 October 2013 - 07:26 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;

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

            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)
                else if (year%100 = 0)
                else if (year%4 = 0)
                else ()
                {
                    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.next.Int();
                B = input.next().charAt(0);
                year = input.nextInt();
            }
            while(A != '/' || B != '/')
            {
               System.out.print("Use forward slashes between month, day, and yea                                r!\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();
            }
}



I am a beginning java user. I am stuck on this program and not sure where to go from here or if the first part of the code i have written is even correct.

Here is a description of what we need to accomplish.

Write a program that will add the digits of a person’s birth date to obtain a single digit to generate a numerology report.

First: Get a Date
Numerology has been used since ancient times to shed light on relationships, health and global events. Each element in a birth date
is believed to possess a special numerical significance. We are going to develop our own rudimentary numerology prediction
program. The first thing to do is ask the user to enter a birth date to process.

You will need to indicate to your user that they need to enter the month, day and year in that order separated by spaces and forward
slashes, which look like this: /. An example would be 12 / 25 / 2112. The spaces must be present between the numeric and
character input.


Second: Validate the Date
The important and time-consuming portion of this program is validating your input from the user. This means that you need to check
to make sure the month is between 1 and 12, the day is appropriate for the month, and the year is between 1880 and 2280,
inclusive.

By “the day is appropriate for the month and year”, this means that if a date of January 32nd
is entered or a date of June 0th is
entered, you should recognize and report that. This also means that you should check to see that if the year is a leap year, you
should allow February 29th
and if it's not a leap year, you should disallow February 29th. See the "Solution Suggestions" for a
website that discusses leap years.

Allow the user to input the entire date before you validate it.

You should continuously re-prompt the user for a date until a valid date is entered. If one part of the date fails (month, day or year),
re-prompt for the entire date again. Do not simply re-prompt for the offending part of the date. Output appropriate error messages
for the incorrect dates. See the example runs for sample error messages.


Third: Crunch the Date
Then, you need to calculate a single digit from the birth date. For example if your birth date is 3/19/1955 you add 3+1+9+1+9+5+5
to get 33. You would then break this apart and add 3+3 to get 6.

You will need to be careful because it is possible to have to “fold” the number more than just once, as in the above example. For
example, if the birth date was 7/5/1942, you would add up the individual digits 7+5+1+9+4+2 to get 28, then you would need to add
2 + 8 to get 10. This is still a two-digit number, and needs to be added again – 1 + 0 – to get a single-digit result of 1.

You can simplify the process by adding the month day and year together first (i.e., 7+5+1942, to get 1954) and then breaking down
and adding that result (1+9+5+4), which results in 19, which needs to be broken down again to get 1+9 which results in 10, which
then results in 1+0, or 1. You should never have to crunch a number more than 3 times and will usually only need to add the digits
once.

This post has been edited by modi123_1: 23 October 2013 - 08:25 PM
Reason for edit:: fixed botched code tags


Is This A Good Question/Topic? 0
  • +

Replies To: question on numerology program

#2 madsamps  Icon User is offline

  • New D.I.C Head

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

Re: question on numerology program

Posted 23 October 2013 - 08:14 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;

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

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)
else if (year%100 = 0)
else if (year%4 = 0)
else ()
{
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.next.Int();
B = input.next().charAt(0);
year = input.nextInt();
}
while(A != '/' || B != '/')
{
System.out.print("Use forward slashes between month, day, and yea r!\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();
}
}


Was This Post Helpful? 0
  • +
  • -

#3 madsamps  Icon User is offline

  • New D.I.C Head

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

Re: question on numerology program

Posted 23 October 2013 - 08:21 PM

If anyone has even any pointers to start with, that would be great! I am very lost and could use any help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1