0

im currently doing some code and am having problem and cant get my head around it. I am very new at this is any help would be appreciated

I'm trying to make a compound condition for the date but cant seem to understand how to do it.

public void rentBook(int theBorrowerNumber, String theReturnDate)
{

        if(theBorrowerNumber <=0)                                         // checks if the borrower number is less or equal to 0
        {
            System.out.println("Invalid borrower number");                // prints the error message
        }
    ///////////////////////////////////////
    returnDate = theReturnDate;                                           // reDate aquires theReDate content
    String day = returnDate.substring(0,2);                               // set the day to the first 2 numbers from the date
    String month = returnDate.substring(2,4);                             // set the month to the second 2 numbers form the date
    int theDay = Integer.parseInt(day);                                   // converts the day string to integer
    int theMonth = Integer.parseInt(month);                               // converts the month string to integer
    //////////////////////////////////////  
        if(theDay <= 0 | theDay >= 32 | theMonth <= 0 | theMonth >= 13)   //setting the parameters the date must be within
        {
            System.out.println("Invalid date");                           // prints out if the date is wrong
        }
        else
        {
            super.setBorrowerNumber(theBorrowerNumber);                  // sets the borrower number in the super class
        }

}   
  • @user3113362: please elaborate what you mean by "compound condition". Also, it would help if you could show the result you would like to get. Are you perhaps just trying to understand how to create logical combinations of conditions (in your case it looks like you might be looking for ORs, "||" not "|"). If so, then please ask the question that way and avoid adding unnecessary code to your question. You are more likely to get a good answer when you only ask the essence of your question. – Christian Fritz Dec 18 '13 at 01:36

1 Answers1

1

The logical or operator is || instead of |

if(theDay <= 0 || theDay >= 32 || theMonth <= 0 || theMonth >= 13)   
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189