5 Replies - 737 Views - Last Post: 26 April 2013 - 07:29 PM Rate Topic: -----

#1 dollymonroe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 14-April 13

Create while loop using the boolean return false from another method

Posted 26 April 2013 - 04:39 PM

Is it even possible to create a loop like that? I get this error when I try to run it:

Numerology.java:60: error: cannot find symbol
while ( validDate == false )
^
symbol: variable validDate

    public void getDate ()
    {
        char slash1;
        char slash2;

        while ( validDate == false )
        {
            validDate(slash1, slash2);

            System.out.print( "Enter the birth date (mm / dd / yyyy): ");
            month = i.nextInt();
            slash1 = i.next().charAt(0);
            day = i.nextInt();
            slash2 = i.next().charAt(0);
            year = i.nextInt();
        }

            //calcNum();
    }

    public Boolean validDate ( char slash1, char slash2 )
    {



Is This A Good Question/Topic? 0
  • +

Replies To: Create while loop using the boolean return false from another method

#2 darek9576   User is offline

  • D.I.C Lover

Reputation: 203
  • View blog
  • Posts: 1,731
  • Joined: 13-March 10

Re: Create while loop using the boolean return false from another method

Posted 26 April 2013 - 04:44 PM

You are calling a method therefore include () and arguments. And why are you returning a Boolean and not a boolean.
while(!validDate('a', 'b')){ //do smoething}

Was This Post Helpful? 1
  • +
  • -

#3 dollymonroe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 14-April 13

Re: Create while loop using the boolean return false from another method

Posted 26 April 2013 - 04:59 PM

I have been typing in String so it was my error.

Now that I have fixed the loop it returns the validation message of bad month, day, or year twice when I enter an invalid date. Is this because the method has two arguments?

    public boolean validDate ( char slash1, char slash2 )
    {
        int count = 0;

        int[] daysPerMonth =
            { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

        if ( month < 1 || month > 12 )
        {
            System.out.printf( "Bad month: %d", month );
            return false;
        }

        else if ( day < 1 || day >= daysPerMonth [month] )
        {
            System.out.printf( "Bad day: %d", day );
            return false;
        }

        else if ( year < 1880 ||  year > 2280 )
        {
            leapYear();
            System.out.printf( "Bad year: %d", year );            return false;
        }

        else if ( slash1 != '/' || slash1 != '/' )
        {
            System.out.println( "Use forward slashes between mm / dd / yyyy!\n" );
            return false;
        }
        else
            return true;


Was This Post Helpful? 0
  • +
  • -

#4 dollymonroe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 14-April 13

Re: Create while loop using the boolean return false from another method

Posted 26 April 2013 - 05:37 PM

Can anyone tell me why my validation is printing twice like this:

Welcome to Numerology Reports R Us. We will determine your special numerology report based on a birth date.
Enter the birth date (mm / dd / yyyy): 13 / 1 / 1989
Bad month: 13
Bad month: 13
Enter the birth date (mm / dd / yyyy): 



By looking at the code above.
Was This Post Helpful? 0
  • +
  • -

#5 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: Create while loop using the boolean return false from another method

Posted 26 April 2013 - 07:10 PM

probably the caller of validDate(), not posted, called it twice
just a guess
Was This Post Helpful? 1
  • +
  • -

#6 dollymonroe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 14-April 13

Re: Create while loop using the boolean return false from another method

Posted 26 April 2013 - 07:29 PM

You are correct. I figured it out by playing around with the code. Always appreciate the help though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1