logic problem in here
hi all
I need to set some restrication in here, the ideal is in winter, in saturday after noon, in sunday , in publick holiday , in some time the warring message will show out
my restrict time is
isRestrictedTime = !isSummer && ((isSaturday &&
!bookingDate.before(STime) && !bookingDate.after(ETime)) ||
!bookingDate.before(STime2) && !bookingDate.after(ETime2)) ||
(isSunday && !bookingDate.before(STime) && !bookingDate.after(ETime) ||
!bookingDate.before(STime2) && !bookingDate.after(ETime2)) ||
((isPublicHoliday) && (!bookingDate.before(STime) && (!bookingDate.after(ETime)) &&
!bookingDate.before(STime2) && (!bookingDate.after(ETime2))));
if (isRestrictedTime)
if (restrictedMemberTypes.contains(memberType) &&
!member.getSubId().startsWith("1")||
isRestrictedTime){
add some error message in here}
the message can sho w, but if I use
if (restrictedMemberTypes.contains(memberType) &&
!member.getSubId().startsWith("1")&&
isRestrictedTime){
add some error message in here}
the error message can't show?
what is the possible problem?
thak you
[1564 byte] By [
TMarya] at [2007-10-3 10:43:08]

No error is shown because apparently, there are at least some cases where the subId of a member starts with something other than 1, and the boolean isRestrictedTime is not checked.
&& and || are [url=http://www.sap-img.com/java/java-boolean-logical-operators.htm]short circuit operators[/url]. If you want for all the conditions to be checked, use & and |.
BTW, the way you wrote isRestrictedTime is not very ...appealing.You should make it more readable by specifying intermediary booleans like isBookingDateAcceptable etc.. You will make it easier on other developers who will have to look at your program.
>No error is shown because apparently, there are at least some cases where the subId of a member starts with something other than 1, and the boolean isRestrictedTime is not checked.why this happen?Thank you
If I understand this well, there are two valid booking ranges; Saturday and
Sunday are important days (sometimes) and the Summer season has
got something to do with it too. Those are five boolean restrictions. Can
you explain us in words, plain English, what that restriction is all about?
kind regards,
Jos
the basic ideal is have a form the sport center can set up two interval restrication time , the data go into database, we call it
Start Time EndTime and StartTime2 and Endtime2.
this part work ok.
the restraction time are
1) if is not summer, if is on saturday, it is after noon , and if the sport center set up the restricate time is 13-14, 16-18 and the user (card hold is not 1) try to make a booking on 13:20 or 16:40 the error message will show, if the booking time is not in 13-14, or 16-18 the error message will show.
2) if is nor summer, if is sunday or publicholiday . if the sport center set up the restricate time is 8-9, 14-15, those card hold is not one try to booking between 8-9 14-15, then the error message will show up.
not I have problem on
my code suppose be
if (restrictedMemberTypes.contains(memberType) &&
!member.getSubId().startsWith("1")&&
isRestrictedTime) {
add some error message in here }
but my error message is not show up
if I change it to
if (restrictedMemberTypes.contains(memberType) &&
!member.getSubId().startsWith("1")||
isRestrictedTime) {
add some error message in here }
the error message can show up when the card type is not 1,
what mistak i made?
thank you
> the restraction time are
> 1) if is not summer, if is on saturday, it is afternoon , and if the sport
> center set up the restricate time is 13-14, 16-18 and the user (card
> hold is not 1) try to make a booking on 13:20 or 16:40 the error
> message will show, if the booking time is not in 13-14, or 16-18 the
> error message will show.
> 2) if is nor summer, if is sunday or publicholiday .if the sport center
> set up the restricate time is 8-9, 14-15, those card hold is not one try
> to booking between 8-9 14-15, then the error message will show up.
<totally nauseous>I must apologize; you've lost me here</totally nauseous>
Can you supply a little list with the different criteria that should be met? e.g.
Summer
Saturday
Sunday
8-9
14-15
etc.
The criteria above are either true or false. Depending on their values a
warning should be displayed or not. Let's solve this nasty little problem
step by step. Please supply that criteria list first; no explanation is needed
yet; just the list.
kind regards,
Jos
Just as a first note: Although, it seems appealing to build a big chunk of conditions to assign a boolean variable, often this makes code far too difficult to understand. You could easily replace the BLOB (;)) by single assignment steps or if-else constructs, so you can optically seperate the different conditional cases.
1.)
> if (restrictedMemberTypes.contains(memberType) &&
>!member.getSubId().startsWith("1")&&
> isRestrictedTime) {
> add some error message in here }
2.)
> if (restrictedMemberTypes.contains(memberType)
> &&
>!member.getSubId().startsWith("1")||
> isRestrictedTime) {
> add some error message in here }
(1) is equal to:if (A and B and C) {}
where A, B, and C have to be true.
(2) is equal to:if ( (A and B) or C ) {}
where either A and B have to be true, no matter if C is true or false, or C has to be true, no matter what A's or B's state are.
This is simply because the and-operator (&&) has a higher precedence than the or-operator (||).
season:Winter, day: saterday after noon,or sunday, or publick holidaytime 8-9 and 13-16all the up condition add together call isRestrictedTimethank you
> >No error is shown because apparently, there are at
> least some cases where the subId of a member starts
> with something other than 1, and the boolean
> isRestrictedTime is not checked.
> why this happen?
> Thank you
Sigh. Because, as I said, you're using short-circuit operators.
> Just as a first note: Although, it seems appealing to
> build a big chunk of conditions to assign a boolean
> variable, often this makes code far too difficult to
> understand. You could easily replace the BLOB (;)) by
> single assignment steps..
And that was my second point in my first response.
But apparently, the OP chose to ignore it, along with the rest.
> And that was my second point in my first response.Oops, you are right. Oversaw this due to the short circuit stuff (which, btw., is a reason for some conditions not being evaluated but do not change the wrong logic applied).
Hi all,
Not >short circuit stuff
I change it from
if (restrictedMemberTypes.contains(memberType) &
!member.getSubId().startsWith("1")&
isRestrictedTime) {
errormessage}
not error show