Numerology report

program wont output results

Page 1 of 1

4 Replies - 9975 Views - Last Post: 09 December 2009 - 02:09 PM Rate Topic: -----

#1 paulolira  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-November 09

Numerology report

Posted 03 December 2009 - 08:18 AM

i'm writting a numerology report for my programming class and i think i got all the code but after i run the program and enter a date it wont tell me the results. i have tried everything but no luck also if i run the program and i enter a wrong date and then a correct date the program just keeps asking me to enter another date instead of telling me the results

for example:

Enter the birth date (mm/dd/yyyy):7 / 27 / 1981

after entering the date is should display "Welcome to the Numerology report for 7/27/1981: and tell me my fortune BUT INSTEAD i wont display anything.


also

lest say i enter 0 / 10 / 2000
then it displays:Bad month:0 which is good but if i enter a good date after that for example 2 / 28 / 2007 then the program just keeps asking me to enter a birth date again and again.

and i have no idea what is wrong
import java.util.Scanner;

public class plira_Numerology
{	
	public static void main (String args[])
	{
	int month;
	int day;
	int year;
	int date;
	int numerology;
	char  symbol;
	int t;

Scanner input =new Scanner(System.in);
System.out.print("Enter the birth date (mm/dd/yyyy):");
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();
if(month<1||month>12||year<1880||year>2280||symbol!='/'||month==2)
t=44;
else{t=45;}

do{
while(month<1||month>12){
System.out.printf("Bad month:%d\n",month);
System.out.print("Enter birth date (mm/dd/yyyy):");
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();
}
while (symbol!='/'){
System.out.print("Use forward slashes between mm/dd/yyyy!\n");
System.out.print("Enter birth date (mm/dd/yyyy):");
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();
}
while(year<1880||year>2280){
System.out.printf("Bad year for %d\n",year);
System.out.print("Enter birth date (mm/dd/yyyy):");
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=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 for %d/%d : %d\n",month,year,day);
System.out.print("Enter birth date (mm/dd/yyyy):");
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=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 for %d/%d : %d\n",month,year,day);
System.out.print("Enter birht date (mm/dd/yyyy):");
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();
}}
while(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 birht date (mm/dd/yyyy):");
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();
}
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 birht date (mm/dd/yyyy):");
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();
}}
}while(t==44);

if(t==45){
System.out.printf("Welcome to the numerology report for %d/%d/%d :\n",month,day,year);
date=month+day+year;
	do{
	date=((date%10)+(date/10));
	  }while(date>=10);
numerology=date;
	
	switch(numerology)
		{
		case 1:
	System.out.print(":1: Your luck is about to change so get ready! ");
	break;
		case 2:
	System.out.print(":2: keep trying you are making it. ");
	break;
		case 3:
	System.out.print(":3: its time to relax! ");
	break;
		case 4:
	System.out.print(":4:Money prolems are about to get solved. ");
	break;
		case 5:
	System.out.print(":5: if you stay optimistic your dream will come true.");
	break;

		case 6:
	System.out.print(":6: although things may seem bad don't worry.");
	break;
		case 7:
	System.out.print(":7: you are about to find the love of your life.");
	break;
		case 8:
	System.out.print(":8: too much fun is not very healthy.");
	break;
		case 9:
	System.out.print(":9: something unexpected will happen today.");
	break;
	}}	
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Numerology report

#2 NoobKnight  Icon User is offline

  • D.I.C Head

Reputation: 49
  • View blog
  • Posts: 238
  • Joined: 14-July 09

Re: Numerology report

Posted 03 December 2009 - 09:12 AM

You need to put your original questions/prompts inside your main loop. Once you get a bad date you never give the user the option to turn the 't' flag to 45.

If you do that, you should also only have this code once in the loop.
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();


Was This Post Helpful? 0
  • +
  • -

#3 paulolira  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-November 09

Re: Numerology report

Posted 06 December 2009 - 02:03 PM

View PostNoobKnight, on 3 Dec, 2009 - 08:12 AM, said:

You need to put your original questions/prompts inside your main loop. Once you get a bad date you never give the user the option to turn the 't' flag to 45.

If you do that, you should also only have this code once in the loop.
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();





so if i do that do i put the code
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();


[/quote]

at the end of the loop?
Was This Post Helpful? 0
  • +
  • -

#4 remorseless  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 129
  • Joined: 08-August 09

Re: Numerology report

Posted 06 December 2009 - 06:02 PM

View Postpaulolira, on 7 Dec, 2009 - 07:03 AM, said:

so if i do that do i put the code
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();



at the end of the loop?


The problem here is the person has to press enter 5 times for example:
9*enter*/*enter*19*enter*/*enter*1994*enter* (It's my birthday, don't judge me :angry: )

Do you see the problem? It's asking for each input by itself so the user has to put in the month, then press enter, then the symbol, then press enter etc etc. I sorta redid your whole code (I have too much spare time :rolleyes:)

/*
 *REMEMBER TO COMMENT, IT'S GOOD PRACTICE
 */

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



Hope I helped :)

This post has been edited by remorseless: 06 December 2009 - 07:34 PM

Was This Post Helpful? 0
  • +
  • -

#5 paulolira  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-November 09

Re: Numerology report

Posted 09 December 2009 - 02:09 PM

View Postremorseless, on 6 Dec, 2009 - 05:02 PM, said:

View Postpaulolira, on 7 Dec, 2009 - 07:03 AM, said:

so if i do that do i put the code
month=input.nextInt();
symbol=input.next().charAt(0);
day=input.nextInt();
symbol=input.next().charAt(0);
year=input.nextInt();



at the end of the loop?


The problem here is the person has to press enter 5 times for example:
9*enter*/*enter*19*enter*/*enter*1994*enter* (It's my birthday, don't judge me :angry: )

Do you see the problem? It's asking for each input by itself so the user has to put in the month, then press enter, then the symbol, then press enter etc etc. I sorta redid your whole code (I have too much spare time :rolleyes:)

/*
 *REMEMBER TO COMMENT, IT'S GOOD PRACTICE
 */

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



Hope I helped :)







THANKS THIS HELPED ALOT!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1