Solved

verfiy if else statement

Posted on 2006-07-06
3
240 Views
Last Modified: 2010-04-01
folks

I have the following:

if (mroApp.equals("WOTRACK"))
            {
                  
                  mroRepName = "woprint";
            }
but i want to add a statement into this:

if (mroApp.equals("WOTRACK"))
            and (mroSite.equals("JFK"))

   mroRepName = "woprint2";

so its an if esle

could anyone advise what the correct way

the pschuedo code is

if app =wotrack then repname=woprint else if app =wotrack and site=jfk then woprint2

all other will not have the site parameter bound

all help will do

rutger

0
Comment
Question by:rutgermons
3 Comments
 
LVL 4

Expert Comment

by:evnafets
ID: 17055800
The logic you specified is bad, because the second condition is a subset of the first.
If the second condition is true, the first condition is also true, and so fires first - you would never get into the second test.
Reversing the tests, putting the more specific one first would work.

I would probably write it like this.

  if ("WOTRACK".equals(mroApp)){
    mroRepName = "JFK".equals(mroSite) ? "woprint2" : "woprint";
  }

Using "WOTRACK".equals(mroApp) rather than mroApp.equals("WOTRACK") makes the code more robust by avoiding a null pointer exception if mroApp is null.
I also used a ternary statement to set the value of the mroRepName variable.

0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 17055965
if (mroApp.equals("WOTRACK")
         && (mroSite.equals("JFK"))
   mroRepName = "woprint2";

I think this is what u wanted.
0
 
LVL 8

Accepted Solution

by:
kaliyugkaarjun earned 500 total points
ID: 17056345
If (mroApp.equals("WOTRACK"))
{
   if(mroSite.equals("JFK"))
       mroRepName = "woprint";
   else
        mroRepName = "woprint2";
}
   
   
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to reset your Windows 10 password when you've forgotten it.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question