Solved

verfiy if else statement

Posted on 2006-07-06
3
234 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
Comment Utility
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
Comment Utility
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
Comment Utility
If (mroApp.equals("WOTRACK"))
{
   if(mroSite.equals("JFK"))
       mroRepName = "woprint";
   else
        mroRepName = "woprint2";
}
   
   
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now